上一篇文章中,我整理了CentOS7.7安装MySQL-5.7.21版本遇到的坑,这里我整理一下CentOS7.7安装MySQL-5.7.28
--1. CentOS7.7 也就是这个映像文件:CentOS-7-x86_64-Minimal-1908.iso
--2. MySQL-5.7.28 也就是这个tar包:mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
上传mysql到linux上:
[root@m00 ~]# cd /opt/software
[root@m00 software]# ls
mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
[root@m00 software]# tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-5.7.28-1.el7.x86_64.rpm
mysql-community-test-5.7.28-1.el7.x86_64.rpm
mysql-community-common-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-client-5.7.28-1.el7.x86_64.rpm
mysql-community-server-5.7.28-1.el7.x86_64.rpm
[root@m00 software]#
这些rpm包,我们依然只需要其中四个:
mysql-community-libs-5.7.28-1.el7.x86_64.rpm
mysql-community-common-5.7.28-1.el7.x86_64.rpm
mysql-community-client-5.7.28-1.el7.x86_64.rpm
mysql-community-server-5.7.28-1.el7.x86_64.rpm
--1. 查询一下mariadb的相关包
[root@m00 software]# rpm -qa | grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
--2. 卸载查询到的mariadb 加--nodeps 强制卸载哦
[root@m00 software]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
CentOS7.7最小版默认安装了mariadb-lib库,而mysql-5.7不兼容这个库,所以我们要卸载
玩Linux的你应该知道,安装包都存在着一定的依赖关系,这里我就直接说了,我们最终是想安装mysql-server包,但是mysql-server依赖mysql-client包,而mysql-client依赖mysql-libs包,而mysql-libs依赖于mysql-common包。因此我们的安装顺序如下:
--1. 先安装mysql-common包
[root@m01 software]# rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
--2. 再安装mysql-libs包
[root@m01 software]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
--3. 然后安装mysql-client包
[root@m01 software]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
--4. 之后安装mysql-server包时,提示需要以下依赖包
[root@m01 software]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
error: Failed dependencies:
/usr/bin/perl is needed by mysql-community-server-5.7.28-1.el7.x86_64
net-tools is needed by mysql-community-server-5.7.28-1.el7.x86_64
perl(Getopt::Long) is needed by mysql-community-server-5.7.28-1.el7.x86_64
perl(strict) is needed by mysql-community-server-5.7.28-1.el7.x86_64
这回,我们看到,mysql-server包只依赖 perl和net-tools 两个软件包,不再依赖libsasl2.so.2了,方便了很多。
我们使用yum来在线安装perl 和 net-tools的相关软件即可
[root@m00 software]# yum -y install perl net-tools
安装完perl,net-tools后,我们再安装mysql-server包,就成功了。
--再次安装mysql-server
[root@m01 software]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.28-1.e################################# [100%]
这回,我们轻车熟路的安装完mysql-5.7.28的四个rpm包后,就可以按照以下步骤,启动服务,找到默认密码,进入MySQL,然后修改成你想要的密码就行了。
[root@m00 ~]# systemctl start mysqld
启动服务后,我们去找初始密码。
1. 去mysqld.log日志文件里查看初始密码,下面root@localhost:后的内容就是你的密码。别复制我的密码...呵呵
[root@m00 ~]# cat /var/log/mysqld.log | grep password
2020-01-01T13:02:09.836826Z 1 [Note] A temporary password is generated for root@localhost: UhctshQYt7%.
2. 登陆,输入密码(可以采用复制的方式,如果你愿意手抄,当我没说)
[root@m00 ~]# mysql -u root -p
Enter password: <==复制那个初始密码,粘贴
我在上一篇文章中说过,CentOS7.7中,mysql5.7的密码策略比较高,我们需要改低点。
1. 我们先修改密码策略为low
mysql> set global validate_password_policy=low;
2. 在查看密码策略
mysql> show variables like '%validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.01 sec)
可以看到密码的长度是8,如果你愿意,你可以将密码长度改为6.
3. 将密码长度改为6
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)
4. 修改你想要的密码吧
mysql> alter user root@localhost identified by '单引号里写密码'
到此为止,mysql-5.7.28 就可以在CentOS7.7里正常使用了。
--------------------------------------------如有疑问,敬请留言--------------------------------------------------------------