Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

1. Install wget first (if any)

yum install wget
Copy the code

2. Download the RPM file of mysql

wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Copy the code

3. Install the RPM of mysql

rpm -ivh mysql80-community-release-el7-3.noarch.rpm
Copy the code

4. Modify the /etc/yum.repos.d/ mysql-community-repo file

vim /etc/yum.repos.d/mysql-community.repo
Copy the code

Set enabled under [mysql57-community] to 1 to enable 5.7

Set enabled under [mysql80-community] to 0 to disable 8.0

If you want to install 8.0, set 5.7 to 0 and 8.0 to 1

After modification :wq is saved and released

5. Installation of mysql

yum -y install mysql-community-server
Copy the code

Here I am installed in Ali cloud conterOS 8 reported error:

All matches were filtered out by modular filtering for argument: mysql-community-server

Error: Unable to find a match: mysql-community-server

Yum module disable mysql

Yum -y install mysql-community-server**

6. Check the Mysql status

systemctl status mysqld.service
Copy the code

7. Start the Mysql

Start: systemctl start mysql. service Stop: systemctl stop mysql. service Run the following command to check the mysql. service status: systemctl status mysql. service systemctl enable mysqld.service

Possible errors:

Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xe" for details.
Copy the code

After all, restart and reinstall can solve 90% of the problems. Because this article is mainly about installation, so uninstall it in another post, and then uninstall it again after completion.

Mysql > uninstall mysql from juejin

8. Log in to the mysql database and change the password of user root

Since it is the first time for us to start mysql, the password of the mysql account has not been configured. We need to find out the temporary password of the root user

grep "password" /var/log/mysqld.log
Copy the code

Note: no temporary password is found or no message is returned after executing this command. Check whether mysql is properly installed and started. If no problem can be found, use the ultimate trick – reinstall mysql.

My temporary password is: 26zTLDVr#BBu

Mysql -uroot -p temporary password

mysql -uroot -p26zTLDVr

Matters needing attention:

A. If the temporary password has special characters that cause login errors, add \ before the special characters, for example; Add \ before

mysql -uroot -pfs; qhho7piuA

Do not have Spaces after b, -u, and -p. Otherwise, an incorrect password will be displayed

Change the password authentication policy before you change the password. Otherwise, the password cannot pass the password authentication policy

set global validate_password_policy=0;
set global validate_password_length=4;
Copy the code

Change the password after the password policy is changed

Alter user 'root'@'localhost' IDENTIFIED by ';Copy the code

After the password is successfully changed, enter quit and use the new password to log in again.

Mysql -uroot -p New passwordCopy the code

9. Set the database user to be accessible under all IP addresses

If you do not set this step, you cannot connect to mysql remotely through Navicat

Root is the user, and % indicates all permissions

Rant all PRIVILEGES on *.* to 'root'@'%' identified by 'just changed password ';Copy the code

Update the mysql system permission table

flush privileges;
Copy the code

Run the service mysqld restart command to restart the mysql service

After the restart is complete, you can connect to mysql remotely.

10. If the ali cloud server needs to add port 3306 to the security group, add both the outbound and inbound directions