Install and configure MySQL8 on CentOS7

Reference

Official website Product Documentation

Add REPO file

Use vi or vim to edit the /etc/yum.repos.d/mysql-community.repo file, copy the following content to the file, then save and exit.

            [mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
        

Perform installation

            yum -y install mysql-community-server
        

Modify the configuration file

Use vi or vim to edit /etc/my.cnf. As MySQL8 compared with the previous version, the default processing methods of login, SQL statement rigor and insufficient field length have changed, so if we need to keep the same as before, do the following configuration. If you do not need to be compatible with the old program, you can ignore it. In the modified configuration of the following example, the first three items are for compatibility with the usage habits of the old version, and the last item is to modify the default storage directory of the database.

            default_authentication_plugin=mysql_native_password
validate_password.policy=LOW
sql_mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
datadir=/mysqldata
        

Start service

            systemctl enable mysqld
systemctl start mysqld
        

Get the default connection password

The login password of MySQL8 native root is stored in the log file, and we need to check it from the log file.

            grep "password" /var/log/mysqld.log
        

Verification Service

So far our installation and configuration have been completed, we use the command line to connect to the MySQL service, and then create a database and account.

            mysql -uroot -p