To install MySQL on a CentOS system, you need to perform environment checks, software source configuration, installation of MySQL, start services and other operations in turn. I will follow the standard process to share the complete and specific installation steps for you in detail.
Installing MySQL database in CentOS system can provide efficient and stable data storage and management services for various applications. The following will introduce the complete steps to install MySQL in a CentOS system in detail, covering the entire process from environment preparation to final configuration completion.
1. Environmental inspection and preparation
Before installing MySQL, you need to check the version of the CentOS system to ensure that the system meets the basic operating requirements of MySQL. Generally speaking, CentOS 7 and above are better compatible with MySQL. At the same time, make sure the system has enough disk space to install MySQL and store data.
In addition, you need to check whether other versions of MySQL or MariaDB are already installed in the system. If it exists, you can uninstall it using the following command:
sudo yum remove mysql mysql-server mysql-libs mysql -connector
After the uninstallation is complete, delete the remaining MySQL files and directories to avoid interference with subsequent installations:
sudo rm -rf /var/lib/mysql sudo rm -rf /etc/
2. Configure MySQL software source
MySQL officially provides a yum source, which allows MySQL to be easily installed and managed by configuring the yum source. First, download the official yum source configuration file of MySQL. For the MySQL version 8.0, you can use the following command:
sudo rpm -Uvh /get/
After the installation is completed, a file will be generated in the /etc// directory, which defines the download source address of the MySQL software package.
By default, the source for MySQL 8.0 Community Edition is enabled. If you need to install another version (such as MySQL 5.7), you can disable the source of MySQL 8.0 and enable the source of MySQL 5.7 using the following command:
sudo yum-config-manager --disable mysql80-community sudo yum-config-manager --enable mysql57-community
3. Install MySQL
After configuring the software source, you can use the yum command to install MySQL server, client and related components:
sudo yum install mysql-community-server
During the installation process, yum will automatically resolve the dependencies of the software package and prompt whether to continue the installation. Enter y and enter to confirm the installation. After the installation is completed, MySQL-related files and directories will be placed in the corresponding location of the system, for example:
- Configuration file: /etc/
- Data directory: /var/lib/mysql
- Executable files: /usr/bin/mysql (client), /usr/sbin/mysqld (server)
4. Start MySQL service
After the installation is complete, the MySQL service needs to be started. You can start, stop, and restart the MySQL service using the following commands and set up power-on self-start:
sudo systemctl start mysqld sudo systemctl stop mysqld sudo systemctl restart mysqld sudo systemctl enable mysqld
You can check the status of the MySQL service through the following command to ensure that the service has started normally:
sudo systemctl status mysqld
If the service is running normally, a message similar to "Active: active (running)" is displayed.
5. Initialize MySQL
After starting MySQL for the first time, initial configuration is required. MySQL 8.0 will automatically generate a temporary password after the installation is completed. You can view the temporary password through the following command:
sudo grep 'temporary password' /var/log/
After obtaining the temporary password, use the password to log in to MySQL:
mysql -u root -p
After logging in successfully, you first need to modify the root user's password to improve security. You can modify your password using the following command (assuming that the password is modified to NewPassword123):
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123';
At the same time, to enhance the security of MySQL, you can also run security configuration scripts:
sudo mysql_secure_installation
This script will prompt you to set password policies, delete anonymous users, prohibit root users from logging in remotely, delete test databases, etc., and select and configure them according to actual needs.
Through the above steps, the installation and basic configuration of MySQL in the CentOS system is completed. In the future, you can create databases and users according to specific application needs, and perform data additions, deletions, modifications and searches.
The above steps cover the core process of installing MySQL on CentOS system. If you encounter an error during the installation process or have specific version requirements, please feel free to talk to me.
This is the article about the MySQL installation steps shared in CentOS system. For more related centos mysql installation content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!