Home >Database >Mysql Tutorial >How to set up a MySQL server on a Linux system
MySQL is an open source relational database management system that is widely used in various applications to store data and information. In this article, we will show how to set up a MySQL server on a Linux system.
Before starting the MySQL installation, you need to perform the following preparation work:
Execute the following command to install MySQL:
sudo apt-get update
sudo apt-get install mysql -server
During the installation process, you need to set the password of the MySQL super user account (i.e. root user), which can be configured through the command mysql_secure_installation.
sudo mysql_secure_installation
You will be asked to enter the password of the MySQL root user, and then there will be a series of questions to answer. It is recommended to select the "Yes" option and set a new password to strengthen MySQL security.
You can use the following command to connect to the MySQL server:
mysql -u root -p
- The u parameter indicates the username to use, and the -p parameter requires you to enter a password.
You can use the following command to add new users and databases:
CREATE DATABASE dbname;
CREATE USER 'username' @'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';
The dbname here is the name of the database you want to create, and the username is your The username to create, password is the password you want to assign to this user.
By default, MySQL server only allows local connections. If you need to access the MySQL server remotely, you need to perform the following operations:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0
sudo service mysql restart
If you are using a firewall, please change port 3306 (the default port used by MySQL )open.
sudo ufw allow 3306/tcp
If you are unable to connect to the MySQL server, try checking the following:
To sum up, MySQL is a high-performance, reliable, and easy-to-maintain relational database management system. It is relatively simple to install and configure the MySQL server. Through the introduction in this article, you can easily set up a MySQL server for use by your applications.
The above is the detailed content of How to set up a MySQL server on a Linux system. For more information, please follow other related articles on the PHP Chinese website!