[MySQL] installation of mysql8 in CentOS 7, which is a must for beginners

Posted by FirePhoenix on Mon, 24 Jan 2022 09:45:34 +0100

preface

In CentOS, the default database is mariadb, so installing mysql is a little more difficult than before. Especially for novices, they just can't do it by looking at the documents. Very helpless, today I specially sorted out the detailed process of installing mysql in CentOS 7 for novices to learn.

Experimental environment

1. Kernel version
[root@gaosh-64 ~]# uname -r
3.10.0-1127.13.1.el7.x86_64
2. Operating system version:
[root@gaosh-64 ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)
[root@gaosh-64 ~]# 
3. Prepare mysql database and version:

mysql80-community-release-el7-3.noarch.rpm
For your convenience, I uploaded it to Baidu cloud disk

Baidu cloud disk link: https://pan.baidu.com/s/1Vt2IOeV2NKZrhewKtd9hzg
Extraction code: x788

4. Unload the package of mariadb in the machine
[root@gaosh-64 ~]# rpm -qa |grep mariadb

rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps

Or use

[root@gaosh-64 ~]# yum -y remove mariadb-libs
5. Close selinux and firewall
[root@gaosh-64 ~]# setenforce 0
setenforce: SELinux is disabled
[root@gaosh-64 ~]# systemctl stop firewalld
[root@gaosh-64 ~]# 
be careful:

The above is all the environment settings. Note that at the beginning of learning, first ensure that the environment is consistent, and then try the situation with different environment after several times of installation.

Just like learning to ride a bicycle, you have to be able to ride before you learn some advanced bicycle playing methods, such as single wheel riding.

Officially install mysql

1. Download and configure mysql8 0 installation source

[root@gaosh-17 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

If you cannot download using wget, you can use the baidu cloud disk mentioned in step 3 of the environment configuration to download the corresponding package from the baidu cloud disk and upload it to the server using the rz command.

[root@gaosh-17 ~]# yum localinstall mysql80-community-release-el7-3.noarch.rpm

`##### 2. Install mysql service and start

[root@gaosh-64 ~]# yum install mysql-community-server
[root@gaosh-64 ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

3. Check the initial password of mysql, which is usually in the log
[root@gaosh-64 ~]# grep 'password' /var/log/mysqld.log 
2020-07-21T11:10:26.022672Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ?*,y;vKoV4ma
4. Log in the database with the initial password:
[root@gaosh-64 ~]# mysql -uroot  -p
Enter password: ?*,y;vKoV4ma
Change to your own password for later use:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY "ZMgaosh123!";
Query OK, 0 rows affected (0.00 sec)

A little thought about password

1. Thinking

mysql8 requires to set the complexity and degree of the password by default, but sometimes the password is too complex and inconvenient for testing. How to make it shorter?

If you make it shorter, you will report an error:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
2. Problem solving

This is actually related to validate_ password_ The value of policy

The following is the modification method:

mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.01 sec)


mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

OK, here our password has been set to what you want. Next, you can use password 123456 to log in to mysql8 and play happily.

Important: try not to change the production environment to a simple password, which is not safe enough.

summary

This article mainly discusses the detailed process of installing MySQL 8 under CentOS7. We need to ensure that the environment is consistent as much as possible.

This article is from ID: Internet old Xin more content is concerned about the official account of the "geek operation and maintenance home".

Topics: Database