Home >Operation and Maintenance >Linux Operation and Maintenance >How to install and configure a MySQL database on Linux
How to install and configure the MySQL database on Linux
Foreword:
MySQL is an open source relational database management system that is widely used in the development and management of Web applications. Installing and configuring MySQL on a Linux system can help us build an efficient and stable database environment. This article will introduce how to install and configure MySQL on Linux, and provide corresponding code examples.
1. Install MySQL
sudo apt-get update
sudo apt-get install mysql-server
2. Configure MySQL
sudo service mysql start
sudo mysql_secure_installation
After executing the above command, you will be asked to enter the MySQL root password to perform subsequent operations. Follow the prompts to complete the security configuration step by step.
3. Connect to MySQL
mysql -u root -p
Enter the MySQL root password after the prompt to successfully connect to the MySQL server.
4. Create a database
CREATE DATABASE database_name;
Where database_name is the name of the database you want to create.
5. Create users and assign permissions
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
where username is the username you want to create, and password is the password you want to set.
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
6. Exit MySQL
exit;
7. Common command examples
SHOW DATABASES;
USE database_name;
SHOW TABLES;
DESCRIBE table_name;
INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3);
8. Summary
This article introduces how to install and configure the MySQL database on Linux, and provides relevant code examples. By following the steps in this article, you can successfully set up a MySQL database environment and use common commands to operate in the database. Hope this article will be helpful to you.
Reference materials:
The above is the detailed content of How to install and configure a MySQL database on Linux. For more information, please follow other related articles on the PHP Chinese website!