关于mysql5.7的初始密码 修改密码安全策略
关键字:mysql初始密码,mysql默认密码,mysql5.7
mysql5.7增强了安全性,root用户的默认密码不再为空。
mysql安装完成以后,会自动生成一个临时密码,也可以称之为初始密码,这个密码仅用于初次登陆mysql使用,必须修改密码才可以进行其他操作。
方法一:
1、查找初始密码:
初始密码记录在mysql的日志文件中。
# less /var/log/mysqld.log |grep password 2016-11-07T09:07:57.847570Z 1 [Note] A temporary password is generated for root@localhost: lku9x*.g!GpH
lku9x*.g!GpH即为初始密码。
2、修改初始密码
此处对密码有复杂度要求
[root@localhost ~]# mysql -uroot -p Enter password: mysql> mysql> set password=password('Mypass.369369');
方法二、
修改mysql配置文件,跳过用户验证
1、vim /etc/my.cnf
添加一行
skip-grant-tables=1
2、重启mysqld服务
#service mysqld restart
3、重新登录mysql此时不需要密码
#mysql
4、修改root密码
mysql 5.7,user表中的密码字段名由原来的password变为了 authentication_string
mysql> desc user \G *************************** 41. row *************************** Field: authentication_string Type: text Null: YES Key: Default: NULL Extra:
修改密码:
mysql> update mysql.user set authentication_string = password('mypassword123') where user = 'root';
5、删除my.cnf配置文件中的
#skip-grant-tables=1
6、重启mysqld服务,密码修改完成。
方法三、
alter user 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
二、修改密码策略:
1、查看当前密码策略
show variables like 'validate_password%';
2、各项值说明
validate_password_policy:密码安全策略,默认MEDIUM策略
策略 | 检查规则 |
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 |
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个
3、修改策略(将策略要求置为LOW,长度要求置为1)
set global validate_password_policy=0; set global validate_password_length=1;
4、
flush privileges;