r3421555 发表于 2017-8-18 12:37:18

MySQL5.7修改密码

MySQL5.7出来蛮久了,今天用官方的RPM包安装玩了一遍,与值之前的版本有些差异,MARK下。


OS PLATFORM:Centos 7.3


安装MySQL 5.7版本,官网http://dev.mysql.com/downloads/repo/yum/

rpm -ivhhttp://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm



YUM安装:

1
yum -y install mysql-community-server






速度不是很快,慢慢等。。。。。。。。。

更改DATADIR

1
sed- i 's/datadir=/var/lib/mysql/datadir=/data/mysql/' /etc/my.cnf




启动数据库
/etc/init.d/mysqld start               #该过程包含初始化数据库

MySQL5.7新特性,为了加强安全性,为root用户随机生成了一个密码,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:


1
2
3
# grep 'temporary password' /var/log/mysqld.log
2017-08-16 T14:51:45.705458Z 1 A temporary password is generated for root@localhost: a&sqr7dou7N_
mysql -uroot -p'a&sqr7dou7N_'




登陆上过后,进行正常操作会受限,提示你必须修改密码后才能进行操作,根据提示修改密码:


1
2
3
4
mysql> SET PASSWORD = PASSWORD('123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> SET PASSWORD = PASSWORD("root");
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements




但是提示根据当前密码策略,设置的密码不允许。
查阅官方文档后发现有以下三种密码策略:
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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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位 。
更改完密码就可以进行数据库的操作了。


1
2
3
4
5
6
7
8
9
10
11
mysql root@localhost:(none)> show DATABASES;
+--------------------+
| Database         |
|--------------------|
| information_schema |
| mysql            |
| performance_schema |
| sys                |
+--------------------+
4 rows in set
Time: 0.009s




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


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




设置完默认密码策略后,就只有 密码长度限制 了。默认为字符长度至少8位。


想要永久关闭密码复杂安全策略,则在配置文件中加入以下并重启mysqld即可:

validate_password=off


mayiwen123456 发表于 2017-8-18 13:06:39

学习了
页: [1]
查看完整版本: MySQL5.7修改密码