1、配置YUM源
1
2
3
4
1
2
3
4# 下载MysqL源安装包
shell> wget http://dev.MysqL.com/get/MysqL57-community-release-el7-8.noarch.rpm
# 安装MysqL源
shell> yum localinstall MysqL57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
1
1shell> yum repolist enabled | grep "MysqL.*-community.*"
看到上图所示表示安装成功。 可以修改vim /etc/yum.repos.d/MysqL-community.repo源,改变默认安装的MysqL版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。改完之后的效果如下所示:
1
shell> yum install MysqL-community-server
3、启动MysqL服务
1
shell> systemctl start MysqLd
查看MysqL的启动状态
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10shell> systemctl status MysqLd
● MysqLd.service - MysqL Server
Loaded: loaded (/usr/lib/systemd/system/MysqLd.service; disabled; vendor preset: disabled)
Active: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago
Main PID: 2888 (MysqLd)
CGroup: /system.slice/MysqLd.service
└─2888 /usr/sbin/MysqLd --daemonize --pid-file=/var/run/MysqLd/MysqLd.pid
6月 36 localhost.localdomain systemd[1]: Starting MysqL Server...
37 localhost1]: Started MysqL Server.
4、开机启动
1
2
1
2shell> systemctl enable MysqLd
shell> systemctl daemon-reload
5、修改root本地登录密码
MysqL安装完成之后,在/var/log/MysqLd.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录MysqL进行修改:
shell> grep 'temporary password' /var/log/MysqLd.log
1
2
shell> MysqL -uroot -p
MysqL> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者
1
MysqL> set password for 'localhost'=password('MyNewPass4!');
注意:MysqL5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:
通过msyql环境变量可以查看密码策略的相关信息:
1
MysqL> show variables like '%password%';
validate_password_policy:密码策略,默认为MEDIUM策略 validate_password_dictionary_file:密码策略文件,策略为STRONG才需要 validate_password_length:密码最少长度 validate_password_mixed_case_count:大小写字符长度,至少1个 validate_password_number_count :数字至少1个 validate_password_special_char_count:特殊字符至少1个 上述参数是默认策略MEDIUM的密码检查规则。
共有以下几种密码策略:
策略
检查规则
0 or LOW
Length
1 or MEDIUM
Length; numeric,lowercase/uppercase,and special characters