推荐方法二
方法一:
1、修改mysql 配置文件,添加 skip-grant-tables
vim /etc/my.cnf
[myslqd]
...................
skip-grant-tables
...................
2、重启数据库
systemctl restart mysqld
3、进入数据库,修改密码
直接 mysql -uroot -p 回车
use mysql

接下来输入:
mysql> update user set authentication_string = password("123456") where user = "root";
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> flush privileges;
4、修改mysql 配置文件,去除 skip-grant-tables
5、重启数据库
systemctl restart mysqld
6、进入数据库,再次修改密码
mysql -uroot -p123456
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
#设置密码复杂度
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
#完成之后再次执行修改密码语句
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
#再次查询库,就没有ERROR 1820 的告警了
mysql>use mysql;
方法二:
1、关闭数据库实例
systemctl stop mysqld
2、特殊模式启动
--skip-grant-tables [跳过授权表]
--skip-networking [禁止远程登录,只允许使用socket 登录]
#临时启动
mysqld_safe --skip-grant-tables --skip-networking &
3、登录数据库修改密码 [密码可以是任意内容]
mysql -uroot -pXXX
mysql> alter user root@'localhost' identified by 'gxkjnj@2021'
mysql> flush privileges;
exit
4、重启数据库
systemctl restart mysqld
5、登录验证
mysql -uroot -pgxkjnj@2021
本文版权归 飞翔沫沫情 作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出 原文链接 如有问题, 可发送邮件咨询,转贴请注明出处:https://www.fxkjnj.com/3363/