Install MySQL 8.0 in centos7 (RPM mode)


Knowledge is everywhere in life, so is work! In the past, I installed MySQL on Linux more than once, which is easy to say. But I wrote an article to summarize and found that there are many details worth learning!

Installation package selection

Why use RPM?

Generally, there are source code compilation and installation, RPM (or dpkg), yum and other ways to install software on linux series. The advantages and disadvantages are mainly reflected in whether the network environment is needed, whether the dependency can be automatically detected, and whether the upgrade and uninstall are convenient. As a non operation and maintenance personnel, they also need to have a basic understanding.

Source code installation support offline, but even if you can automatically create makefile and other files to simplify the installation, the whole process is more complex, upgrade and uninstall more troublesome. For some software that is not officially released, you can only choose this way.

Yum mode can automatically monitor dependencies, and the installation information can be written into the system software management program during the installation process, so it is convenient to upgrade and uninstall. The disadvantage is that most of the cases need a good network environment, especially some software without domestic image, the speed is moving. (in fact, in some cases, you can also use Yum offline in the directory where the RPM package is located, provided that all kinds of dependencies are available locally).

Rpm is equivalent to the official compiled installation package. It supports offline and can detect dependencies, but some software does not have RPM package. So to a certain extent, RPM has the advantages of the above two ways.

In practice, it should be selected according to the specific environment. Generally speaking, RPM takes precedence over the source code.

This installation environment:

Centos7.8 2003 (minimum installation, root privilege)
MySQL community version 8.0.16

Here, you can choose to upload the downloaded official packaged bundle file, or you can download several unpackaged files on the official website. mysql-8.0.16-2.el7.x86_ 64.rpm- bundle.tar

Or download online (you can also copy the address after WGet to the browser address bar locally, and the download will start automatically)



Note that the decompression command here is – xvf without Z

tar -xvf    mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar

After decompression, it contains 8 files,


Pre installation Environmental Inspection


After the acquisition of MySQL, the original authors of MySQL worried about the risk of closed source, and developed MariaDB on the branch of MySQL. Later, some Linux distributions took MariaDB as the default database system. In theory, MariaDB is compatible with MySQL, and even has better performance in some aspects. (of course, I haven’t tested it.)

rpm -qa | grep -i mariadb

The possible results are as follows


Remove dependence

rpm -ev  --nodeps mariadb-libs-5.5.65-1.el7.x86_64


Installation sequence

It should be installed in the order of common – > LIBS – > client – > server. Otherwise, the installation process will remind you of the dependency order, and others are not required.

rpm -ivh mysql-community-common-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.16-2.el7.x86_64.rpm

As mentioned at the beginning of the article, you can also use the yum command instead of RPM (not required) under the unzipped installation package file

Start and change password


 systemctl start mysqld

View status

systemctl status mysqld

Install MySQL 8.0 in centos7 (RPM mode)

View initial random password

 cat /var/log/mysqld.log | grep password

The result is similar to the following, then the initial password is tc0; + KB? Bqcg

2020-09-02T05:30:06.739311Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: tC0;+kB?BqCg

Log in as root

mysql -u root -p

Paste or enter the initial password. Note that for Linux security, there may be no response on the MySQL command line, or the password has been entered
Install MySQL 8.0 in centos7 (RPM mode)

Change Password

After logging in with the randomly generated password for the first time, you must modify the password, otherwise you cannot do other operations.
Install MySQL 8.0 in centos7 (RPM mode)

Password requirements

According to the default password component of mysql8.0, the password must contain numbers, uppercase and lowercase letters, special characters, and the length should not be less than 8 digits, otherwise the password will be prompted that it does not conform to the rules. It is recommended to set the password in this way. If you want to set the password to 123456, please see the last part of this article, password.

Taking 123456 as password test

ALTER user 'root'@'localhost' IDENTIFIED BY '123456';

Install MySQL 8.0 in centos7 (RPM mode)

Here, we set the password to root.123456. Note that R is capitalized and there is a full stop after t.

ALTER user 'root'@'localhost' IDENTIFIED BY 'Root.123456';

Open remote login permission

At this time, you can only log in as the root role. For the same reason, for security, the root role of MySQL can only log in locally. The normal way is to use the root authority to assign other different roles for remote login.

But here is still forced to open the root role of remote login permissions, otherwise write the role assignment related content, the article will become too long do not look at the series.

The essence of open permission is to modify in MySQL databaseuserOf the tablehostProperty, so that it can be connected by IP outside the local

use mysql;
select host,user from user;
update user set host='%' where user ='root';

After the above statement is executed, refresh permission is executed:

flush privileges;

Open firewall port

After the root remote login permission is turned on, it cannot be directly connected to the outside world, because the port number 3306 of MySQL is turned off by default in Linux.

Note: to use Alibaba cloud and other cloud servers, you also need to open the port in the console by security group policy, which is omitted here. Query whether port 3306 is on

 firewall-cmd --query-port=3306/tcp

Open 3306

firewall-cmd --zone=public --add-port=3306/tcp --permanent

Reload firewall

firewall-cmd --reload

At this point, our program can directly connect to MySQL.

Profile change (not required)

To modify the location of MySQL data and logs, the configuration file is / etc/ my.cnf , directly modify the save location.

vim /etc/my.cnf

Install MySQL 8.0 in centos7 (RPM mode)

The following is not required.

Remote connection of Navicat and other tools (not required)

When using Navicat or sqlyog tools, the newer version can connect directly, so you can use Navicat to test whether the connection is successful before starting this step.

However, when the old version of Navicat connects to mysql8.0, it may not match the encryption rules of MySQL, resulting in the connection failure. The encryption rules here refer to the algorithm used to encrypt and save your password.

Change the encryption rules of MySQL

View encryption rules

show variables like "default_authentication%";

The result may be
Install MySQL 8.0 in centos7 (RPM mode)

Modify the rules

alter user 'root'@'localhost' IDENTIFIED WITH mysql_ native_ Password by 'your password';

The connection is successful with Navicat.

Password problem (not required)

Change password rules

Note: if you set a complex password according to the above rules, this step can be omitted directly.

Again, it is recommended to set the password to a more complex one (as long as you don’t forget). To still set the password to simple, look down.

Log in to MySQL

View password rule requirements (password related components have been installed by default under normal circumstances)

SHOW VARIABLES LIKE 'validate_password.%';

Install MySQL 8.0 in centos7 (RPM mode)

validate_password.policyValue of

You can use numeric values 0, 1, 2 or corresponding symbolic values low, medium, strong to specify validate_ password.policy value

Policy Tests Performed
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file

If you want to use a simple password similar to 123456, you need to change the password rules and password length

Mysql8.0 and later

set global validate_password.policy=0;
set global validate_password.length=1;

In fact, even if the password length is set to 1, its minimum length will not be less than the value of the following function, that is, the default length will never be less than 4

validate_password.number_count+ validate_password.special_char_count
+ (2 * validate_password.mixed_case_count)

5.7 and earlier

set global validate_password_policy=0;
set global validate_password_length=1;

Change password

The password here is changed to 123456

ALTER user 'root'@'localhost' IDENTIFIED BY '123456';


Compared with the whole pipelining installation process, what is more worth pondering is that just one password setting and saving, MySQL provides different components, sets different rules and strategies, and tries to balance convenience and security to the greatest extent. In a sense, it is also an ingenuity worth learning!