在centos7以后的版本,通过yum源安装的MySQL (5.7)后,首次登陆MySQL,需要先查看日志文件,找到临时密码,登陆后,再修改密码。或者,修改密码策略,当然,你也选择不修改密码策略,我是做测试用,所以简单密码比较方便。具体操作如下:
更改密码:
1、启动MySQL
2、查看临时密码
grep 'temporary password' /var/log/mysqld.log
2017-05-06T05:58:54.621766Z 1 [Note] A temporary password is generated for root@localhost: +AqLt/ftS1)k
3、用临时密码登陆MySQL
mysql -u root -p +AqLt/ftS1
4、修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123';
5、测试登陆
修改密码策略:(先要修改临时密码,才能查看密码策略,才能修改为简单密码!!!)
1、查看当前密码策略
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_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 | MEDIUM |
| validate_password_special_char_count | 1 |
+---------------------------------------+--------+
2、修改策略(在配置文件中增加以下语句)
vi /etc/my.conf
validate_password = off
说明:off or 关闭; 0 or LOW; 1 or MEDIUM; 2 or STRONG
另,MySQL官网密码策略详细说明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。