CentOS 7 Detailed steps for installing MySQL

  • 2021-11-01 05:19:40
  • OfStack

In CentOS 7, when we install MySQL, we will install MariaDB by default. It is an open source version introduced by the author after MySQL was acquired. However, we may still want to install a more authentic MySQL

Download and install MySQL official Yum Repository

We can download the link of Yum Repository on the official website of MySQl. In fact, in fact, the


wget -i -c https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm​

Using the command above, we downloaded Yum Repository, and then we can use yum for installation. In fact, in fact, the


yum -y install mysql80-community-release-el7-1.noarch.rpm

The next step is to start installing MySQL


yum -y install mysql-community-server​

MySQL Settings

Start MySQL


systemctl start mysqld.service

View the running status


systemctl status mysqld.service

At this point, our database is up and running, but we need to find the password of our root user in the log if we want to enter our database. In the new version, the root user password is generated by default.


grep "passsword" /var/log/mysqld.log​

We can view the password of our root user through the above command.

mysql-uroot-p Enter the password into the database. In fact, in fact, the

Enter the initial password, and nothing can be done at this time, because MySQL must change the password by default before it can operate the database:


mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

Here, the password should have a certain complexity.

After changing the password, we can operate normally.

However, there is still a problem at this time, because Yum Repository is installed, and every yum operation will be automatically updated in the future, so this needs to be uninstalled:


yum -y remove mysql80-community-release-el7-1.noarch

Startup startup


shell> systemctl enable mysqld
shell> systemctl daemon-reload

Add a remote login user

By default, only root accounts are allowed to log in locally. If you want to connect to mysql on another machine, you must modify root to allow remote connection, or add an account to allow remote connection. For security reasons, I add a new account:


mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;

mysql8 is a bit different from the original version. The security level of mysql8 is higher, so when creating remote connection users, you can't use the original command (creating users and empowering at the same time):

User must be created first (password rule: mysql 8.0 above password policy limit must be case plus numeric special sign):

Create a user
mysql > create user chenadmin@'%' identified by 'Chenadmin0.';
Perform an assignment
mysql > grant all privileges on *.* to chenadmin@'%' with grant option;
Last refresh
mysql > flush privileges;

Configure the default encoding to utf8

Change the/etc/my. cnf configuration file and add encoding configuration under [mysqld] as follows:


yum -y install mysql80-community-release-el7-1.noarch.rpm
0

Restart the mysql service


yum -y install mysql80-community-release-el7-1.noarch.rpm
1

Related articles: