Centos7.3安装并配置mysql5.7

1、配置YUM源

1、下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

2、安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm

3、安装MySQL
yum install mysql-community-server

4、启动MySQL服务
systemctl start mysqld
查看MySQL的启动状态
systemctl status mysqld
5、开机启动
systemctl enable mysqld
刷新配置systemctl daemon-reload

6、修改root本地登录密码
命令grep 'temporary password' /var/log/mysqld.log

[root@rootlog]# grep 'temporary password' /var/log/mysqld.log
2017-08-16T06:12:55.554378Z 1 [Note] A temporary password is generated for root@localhost: KA)Qiwcga47P

[root@rootlog]# mysql -uroot -pKA)Qiwcga47P

注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误

修改root密码:

ALTER USER ‘root’@’localhost’ IDENTIFIED BY '密码'; 
set password for ‘root’@’localhost’=password('密码'); 

通过msyql环境变量可以查看密码策略的相关信息:

mysql> show variables like ‘%password%’; 

7、支持root用户允许远程连接mysql数据库

grant all privileges on *.* to 'root'@'%' identified by '密码' with grant option;
刷新配置:
flush privileges;

默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

补充:密码策略

Policy Tests Performed
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file

查阅官方文档后发现有以下三种密码策略:

Policy Tests Performed
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file

当前密码策略默认为1 也就是 MEDIUM

mysql root@localhost:(none)> show VARIABLES like "%password%"
+---------------------------------------+---------+
| Variable_name                         | Value   |
|---------------------------------------+---------|
| default_password_lifetime             | 0       |
| disconnect_on_expired_password        | ON      |
| log_builtin_as_identified_by_password | OFF     |
| mysql_native_password_proxy_users     | OFF     |
| old_passwords                         | 0       |
| report_password                       |         |
| sha256_password_proxy_users           | OFF     |
| 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       |
+---------------------------------------+---------+
13 rows in set
Time: 0.030s

所以你更改密码的策略是 数字 小写字母 大写字母 特殊字符 长度至少8位 。
更改完密码就可以进行数据库的操作了。

接下来修改默认密码策略(当然实际环境是不推荐修改为更低安全策略的)

mysql root@localhost:(none)> set global validate_password_policy = 0;
Query OK, 0 rows affected
Time: 0.003s

现在设置完默认密码策略后,就只有 密码长度限制 了。默认为字符长度至少8位。
其中:
validate_password_number_count指定了密码中数据的长度,
validate_password_special_char_count指定了密码中特殊字符的长度,
validate_password_mixed_case_count指定了密码中大小字母的长度。

这些参数,默认值均为1,所以validate_password_length最小值为4,如果你显性指定validate_password_length的值小于4,尽管不会报错,但validate_password_length的值将设为4。

mysql root@localhost:(none)> set global validate_password_length = 3;
Query OK, 0 rows affected
Time: 0.004s

mysql root@localhost:(none)> show VARIABLES  like "validate_password_length"
+--------------------------+---------+
| Variable_name            |   Value |
|--------------------------+---------|
| validate_password_length |       4 |
+--------------------------+---------+
1 row in set
Time: 0.010s

如果修改了validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一个值,则validate_password_length将进行动态修改。

通过my.cnf 配置文件设置密码策略的级别

添加:
validate_password_policy=2

或者
当然你也可以通过 my.cnf 配置文件关闭 validate_password 插件。
只需要添加一行

validate_password = off

编辑完配置文件后,重启mysqld服务即可生效。

mysql root@localhost:(none)> show VARIABLES  like "validate_password%"
+-----------------+---------+
| Variable_name   | Value   |
|-----------------+---------|
+-----------------+---------+
0 rows in set
Time: 0.008s

你可能感兴趣的:(Centos7.3安装并配置mysql5.7)