Note: root privileges are required
Table of contents
3. After the installation is complete, start MySQL and configure it to start automatically at boot.
4. Check the running status of MySQL
1. Get the initial password for MySQL
2. Log in to the MySQL database system
4. [Extension], configure a simple password for root
5. Allow root remote login and set the remote login password
6. Exit the MySQL console page
1. Installation
1. Configure yum warehouse
# Update key rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 # Install Mysql8.x version yum library rpm -Uvh https://dev.mysql.com/get/ mysql80-community-release-el7-2.noarch.rpm
Since MySQL is not in the official CentOS repository, we use the above rpm command:
-
Import the key to the MySQL warehouse
-
Configure the yum warehouse of MySQLQ
If the following happens when updating the key
Solution (distribution network): http://t.csdn.cn/2ZQxw
2. Use yum to install MySQL
# yum安装Mysql
yum -y install mysql-community-server
3. After the installation is complete, start MySQL and configure it to start automatically at boot.
systemctl start mysqld # Start systemctl enable mysqld # Start automatically at boot
After MySQL is installed, it will be automatically configured as mysqld
a service named:, which can be managed by systemctl
4. Check the running status of MySQL
systemctl status mysqld
2. Configuration
Mainly configure the password of the administrator user root and configure the permissions to allow remote login.
1. Get the initial password for MySQL
# Use the grep command to filter the temporary password keyword in the /var/log/mysqld.log file to get the initial password
grep 'temporary password' /var/log/mysqld.log
The box in the picture is the initial password value, copy it down
2. Log in to the MySQL database system
# Execute
mysql -uroot -p
# Explanation
# -u, the logged in user, the administrator user of the MySQL database is the same as Linux, it is root
# -p, means to use the password to log in
# After the execution is completed, enter (paste) the initial password just obtained , you can enter the MySQL database. When entering the password, the password will not be displayed.
3. Change root password
Don’t forget; key
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
-- The password needs to be: more than 8 characters, with uppercase letters, special symbols, and cannot be a continuous simple statement such as 123, abc
After setting the new password, you can press ctrl+d to log out, and then log in again with the new password to verify it.
4. [Extension], configure a simple password for root
We can set a simple password for root, such as 123456.
Please note that this configuration is only for MySQL in a test environment or learning environment. If it is for formal use, please do not set a simple password.
set global validate_password.policy=0; # The password security level is low set global validate_password.length=4; # The minimum password length is 4 characters.
Then repeat the change password command
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
At this point, the simple password has been changed successfully. You can log out and log in again to verify it.
5. Allow root remote login and set the remote login password
By default, the root user does not run remote login and is only allowed to log in to the MySQL system on the Linux server where MySQL is located.
Please note that allowing root remote logins poses a security risk
# Set up root remote login for the first time, and configure the remote password. Use the following SQL command create user 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password!'; -- The password needs to be: greater than 8 characters, with uppercase letters, with Special symbols cannot be consecutive simple statements such as 123, abc (except when a simple password is configured) # To subsequently change the password, use the following SQL command ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
Fill in the IP address in the first box, but the remote login IP address has changed and you need to reset the IP. You can use wildcards to represent all IP addresses.
Subsequent changes to the password are as follows:
6. Exit the MySQL console page
# Exit command exit # Or exit through shortcut keys: ctrl + d
7. Check the port
MySQL is bound to port 3306 by default. You can check the network status of MySQL through port occupancy.
netstat -anp | Grip 3306
At this point, MySQL is installed and available. Please keep the MySQL root password properly.