The nanny-level tutorial for installing MySQL 5.7 version on CentOS system is clear and simple starting from beginners.

Note: root privileges are required

ps: Most of the pictures are screenshots taken when installing MySQL 8.0 version for reference only. For actual instructions, please refer to the code in red font. The installation steps for versions 8.0 and 5.7 are the same, and the codes are different in some places.

Install MySQL8.0 version: http://t.csdn.cn/CSOqM

Table of contents

1. Installation

1. Configure yum warehouse

2. Use yum to install MySQL

3. After the installation is complete, start MySQL and configure it to start automatically at boot.

4. Check the running status of MySQL

2. Configuration

1. Get the initial password for MySQL

2. Log in to the MySQL database system

3. Change root password

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

7. Check the port  


1. Installation

1. Configure yum warehouse

# Update key
 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
 
# Install Mysql yum library rpm -Uvh http://repo.mysql.com//mysql57-community- release-el7-7.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/wmVSC

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 mysqlda 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 

# Execute ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' in the MySQL console
 ; 	-- 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.

# If you want to set a simple password, you need to lower the password security level of Mysql 
 set global validate_password_policy=LOW;   # The password security level is low  
set global validate_password_length=4;   # The minimum password length is 4 digits 
# Then you can use a simple password (course Use a simple password in production, for convenience, do not do this in production) ALTER USER 'root'@'localhost' IDENTIFIED BY 'simple password';

 

 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

# Authorize root to log in remotely
 grant all privileges on *.* to root@"IP address" identified by 'password' with grant option;  
# The IP address is the IP address that is allowed to log in, or you can fill in % to indicate that any address is allowed 
# Password indicates Set a separate password for remote login, which can be different from the password for local login 

# Refresh permissions to take effect flush privileges;

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.

Guess you like

Origin blog.csdn.net/2301_77160836/article/details/131660556