Centos MySQL8 配置

修改密码

1.查看初始密码

grep 'temporary password' /var/log/mysqld.log

2.连接 MySQL, 输入下面代码, 回车后输入上面密码

mysql -uroot -p

3.选数据库

use mysql;

4.将authentication_string置空

update user set authentication_string='' where user='root';

注:在mysql8.0以上版本,

update mysql.user set password='newpassword' where user='root';
 
update mysql.user set password=PASSWORD('newpassword') where User='root';

这两条命令已经不起作用了

5.修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

会出现报错如下:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

这个其实与validate_password_policy的值有关

有以下取值:

Policy Tests Performe(要求)
0 or LOW Length
1 or MEDIUM numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters

默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
有时候,只是为了自己测试,不想密码设置得那么复杂,譬如说,我只想设置root的密码为123123.

这是时候,Wimbledon可以在第一次使用进入数据库的时候修改几个全局变量就行,或者再次跳过权限表进入到数据库!

mysql> show variables like "%validate%";
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| query_cache_wlock_invalidate         | OFF    |
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |   ##密码的最小长度,改成6
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |   #这个改成0,就可以接受简单的密码
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+
#修改全局变量
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)

mysql> set global  validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like "%validate%";
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| query_cache_wlock_invalidate         | OFF   |
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 6     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
8 rows in set (0.00 sec)

mysql> alter user 'root'@'localhost' identified by '123123';  #重新修改密码,不会再有错误!
Query OK, 0 rows affected (0.01 sec)

from:

https://blog.csdn.net/ssiyla/article/details/82931439

https://www.cnblogs.com/mzxiaoze/p/10413399.html

原文地址:https://www.cnblogs.com/hankleo/p/13842023.html