Installing MySQL under CentOS
MySQL is a popular relational database system and is the backend database used by many websites and applications. Installing MySQL in the CentOS operating system is very simple. This article will introduce the steps to install MySQL in CentOS.
Step 1: Install MySQL
The first step is to install MySQL. It can be installed using the following command:
sudo yum install mysql-server
This will automatically install MySQL and also automatically install the required dependencies. After the installation is complete, start the MySQL service:
sudo systemctl start mysqld
Run the following command to check whether MySQL is running:
sudo systemctl status mysqld
If MySQL is running and "active (running)" will be displayed. If MySQL is not running, you can start it with the following command:
sudo systemctl start mysqld
Step 2: Set the initial root password
After installing MySQL, you need to set the initial root password . This can be set using the following command:
sudo mysql_secure_installation
This will guide you through a series of questions to set the root password. First, it will ask you to enter your current root password, if you have not set a password, you can leave it blank and continue.
Next, it will ask you to choose a new password and confirm the new password. Make sure your password is long and complex enough to stay secure.
After completing the setup, MySQL will remove anonymous users, prevent unauthenticated users from logging in, and remove the root user from remote access.
Step 3: Test MySQL
After installing and setting up MySQL, you can test whether MySQL is working properly. Use the following command to try to connect to MySQL:
mysql -u root -p
The system will prompt you to enter the password, enter the password you just set. After the connection is successful, the MySQL command line prompt will be displayed.
You can now run SQL commands on the MySQL command line, such as creating a database, creating a table, inserting data, etc.
Step 4: Open the firewall port
By default, CentOS’s firewall may block access to MySQL port 3306, so this port needs to be opened. Open the port using the following command:
sudo firewall-cmd --add-port=3306/tcp --permanent
sudo firewall-cmd --reload
Now you should be able to download the port from Another computer is connected to the MySQL server and has access to port 3306.
Conclusion
This article introduces the steps to install MySQL under the CentOS operating system. Using the steps described in this guide, you can easily install MySQL on your CentOS system and start using this popular relational database system.
The above is the detailed content of Install mysql under centos. For more information, please follow other related articles on the PHP Chinese website!