Databases 6 min read

MySQL Installation, Configuration, and Basic SQL Commands Guide

This guide explains how to download, install, and verify MySQL on Windows, macOS, and Linux, configure the server and user permissions, and demonstrates essential SQL commands for creating databases, tables, and manipulating data, providing a comprehensive introduction for beginners.

php Courses
php Courses
php Courses
MySQL Installation, Configuration, and Basic SQL Commands Guide

MySQL is a widely used relational database management system (RDBMS) known for its high performance, reliability, and ease of use. Whether developing small applications or large enterprise systems, MySQL is a preferred tool for database management. This article introduces MySQL fundamentals, including installation, configuration, and basic SQL statements.

1. MySQL Installation

1. Download MySQL

Visit the official MySQL website (https://dev.mysql.com/downloads/mysql/) and select the version appropriate for your operating system (Windows, macOS, or Linux).

For beginners, the free MySQL Community Server is recommended.

2. Installation Steps

Windows: Run the installer, choose "Developer Default" to install MySQL Server and related tools (e.g., MySQL Workbench). Follow the prompts and set a password for the root user.

macOS: Use the .dmg installation package and follow the wizard.

Linux: Install via package manager, for example on Ubuntu:

sudo apt update<br/>sudo apt install mysql-server<br/>

3. Verify Installation

After installation, open a terminal or command prompt and run the following command to check if MySQL is installed correctly: mysql --version<br/> If the MySQL version number is displayed, the installation was successful.

2. MySQL Configuration

1. Start MySQL Service

Windows: Start the MySQL service via the Services management tool or run: net start mysql<br/> Linux/macOS: Start the service with:

sudo systemctl start mysql<br/>

2. Log In to MySQL

Log in as the root user using: mysql -u root -p<br/> Enter the root password set during installation.

3. Create New User and Database

For security, create a new user and grant database privileges:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';<br/>CREATE DATABASE mydatabase;<br/>GRANT ALL PRIVILEGES ON mydatabase.* TO 'newuser'@'localhost';<br/>FLUSH PRIVILEGES;<br/>

4. Configuration File Adjustments

The MySQL configuration file is typically located at /etc/mysql/my.cnf (Linux) or my.ini (Windows) in the installation directory. Adjust memory, connection limits, and other parameters as needed to optimize performance.

3. Basic SQL Statements

1. Database Operations

Create database: CREATE DATABASE dbname;<br/> Drop database: DROP DATABASE dbname;<br/> Use database:

USE dbname;<br/>

2. Table Operations

Create table:

CREATE TABLE tablename (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    age INT
);

Drop table: DROP TABLE tablename;<br/> Describe table structure:

DESCRIBE tablename;<br/>

3. Data Operations

Insert data:

INSERT INTO tablename (name, age) VALUES ('Alice', 25);<br/>

Select data: SELECT * FROM tablename;<br/> Update data:

UPDATE tablename SET age = 26 WHERE name = 'Alice';<br/>

Delete data:

DELETE FROM tablename WHERE name = 'Alice';<br/>

4. Conditional Query and Sorting

Conditional query: SELECT * FROM tablename WHERE age > 20;<br/> Sorting:

SELECT * FROM tablename ORDER BY age DESC;<br/>

4. Summary

MySQL is a powerful and easy-to-learn database management system. Through this article, you have learned how to install, configure, and use basic SQL statements in MySQL. Whether for personal projects or enterprise applications, MySQL provides reliable data storage and management. You can now explore advanced features such as index optimization, transaction handling, and stored procedures to further improve performance and security.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Databaseconfiguration
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.