Home  >  Article  >  Database  >  How to install and configure MySQL in CentOS

How to install and configure MySQL in CentOS

PHPz
PHPzOriginal
2023-04-21 10:11:06925browse

CentOS is a stable and reliable Linux operating system, and many developers choose to develop and deploy on it. MySQL is a very popular database management system that is widely used in web applications, data warehouses, and integration with cloud infrastructure.

This article will introduce how to install and configure MySQL on CentOS.

Step 1: Install MySQL database

Before installing MySQL, in order to avoid software package conflicts and incompatibilities, we need to run the following command to upgrade the system software package to the latest version.

yum -y update

Next, execute the following command to install the MySQL database.

yum -y install mysql-server mysql

At this time, MySQL has been installed, and then we need to configure some MySQL.

Step 2: Configure the MySQL database

First, start the MySQL service.

systemctl start mysqld.service

Then, execute the following command to set MySQL to start automatically at boot.

systemctl enable mysqld.service

Next, we need to perform some security configuration on MySQL. This is very important, because security is often more important than convenience. Execute the following commands to configure security.

mysql_secure_installation

Executing this command will prompt you to enter the MySQL Root password. If you have not set it yet, please set a password. Then follow the instructions below.

  • Do you want to change the password of the root account? (Select yes)
  • What is your desired new password? (Enter new root password)
  • Enter the new password again to confirm (Re-enter new password)
  • Want to delete the anonymous user? (Select yes)
  • Disable remote Root login? (Select yes)
  • Delete the test database and let MySQL reload the permissions table? (Select yes)

At this point, we have completed the installation and basic configuration of MySQL.

Step 3: Use MySQL

Now we can run the following command to test whether MySQL can connect normally.

mysql -h localhost -u root -p

Enter the MySQL Root password you just set. After entering the MySQL shell, execute the following command to see if MySQL is working normally.

SHOW DATABASES;

If the system database can be displayed normally, it means that MySQL is installed and configured successfully.

Summary

This article introduces the process of installing and configuring the MySQL database on CentOS. As a powerful database management system, MySQL requires us to be very careful during installation and configuration, especially in security configuration. I hope this article can help you successfully install and configure the MySQL database on CentOS.

The above is the detailed content of How to install and configure MySQL in CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn