@[toc]

preface

In CentOS, the default database is Mariadb, so installing mysql is a little more difficult than before, especially for beginners. Today I have compiled the detailed process of installing mysql in centos7 for beginners to learn.

Experimental environment

1. Kernel version
[root@gaosh-64 ~]# uname -r3.10.0-1127.13.1. El7. X86_64Copy the code
2. Operating system Version
[root@gaosh-64 ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)
[root@gaosh-64 ~]# 
Copy the code
3. Prepare the mysql database and version:

Mysql80-community-release-el7-3.noarch. RPM For your convenience: I uploaded it to Baidu cloud disk

Baidu cloud disk links: pan.baidu.com/s/1Vt2IOeV2… Extract code: X788

4. Uninstall the mariadb package from the machine
[root@gaosh-64 ~]# rpm -qa |grep mariadb

rpm -eMariadb - libs - 5.5.60-1. El7_5. X86_64 -- nodepsCopy the code

Or use

[root@gaosh-64 ~]# yum -y remove mariadb-libs
Copy the code
5. Disable selinux and the firewall
[root@gaosh-64 ~]# setenforce 0
setenforce: SELinux is disabled
[root@gaosh-64 ~]# systemctl stop firewalld
[root@gaosh-64 ~]# 
Copy the code
Note:

The above is all the environment Settings, attention, at the beginning of learning, first to ensure that the environment is consistent, such as a few times after the installation of skilled to try the environment is not the same.

Just like learning to ride a bike, you need to be able to ride before you can learn some advanced cycling tricks, such as riding on one wheel.

Install mysql

1. Download and configure the mysQL8.0 installation source

/ root @ gaosh – 17 ~ # wget dev.mysql.com/get/mysql80…

If you can’t use wGET to download, you can use the Baidu cloud disk mentioned in step 3 of the environment configuration, download the corresponding package from baidu cloud disk, and use the Rz command to upload to the server.

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

‘##### 2. Install and start the mysql service

[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
[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. 2020-07-21t11:10:26.022672z 6 [Note] [my-010454] [Server] A temporary password is generatedforroot@localhost: ? *,y; vKoV4maCopy the code
4. Use the initial password to log in the database:
[root@gaosh-64 ~]# mysql -uroot -pEnter password: ? *,y; vKoV4maCopy the code
Change it to the password you will use later:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY "ZMgaosh123!";
Query OK, 0 rows affected (0.00 sec)
Copy the code

A little thought about passwords

1. Think about

Mysql8 requires you to set the complexity of the password by default, but sometimes the password is too complex to be convenient for testing. How to make it shorter?

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

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

This is actually related to the value of validate_password_policy

Here’s how:

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)

Copy the code

OK, at this point we have set our password to what we want, next we can use password 123456, login mysql8 happy play.

Important: do not change the production environment to a simple password as far as possible, it is not safe enough.

conclusion

This article focuses on the detailed process of installing MySQL8 under CentOS7, which requires you to make sure your environment is as consistent as possible. The height is very cold, I am gao Sheng cold, welcome to leave a message and I communicate together, like the likes of the collection.