记一次重置mysql8密码的操作

  1. 停止服务
1
service mysqld stop or systemctl stop mysqld.service
  1. 启动服务,不检查授权表
1
mysqld --skip-grant-tables --skip-networking &

报错:
sock 权限问题

1
sudo chown -R mysql:mysql /var/lib/mysql/
  1. 执行重置
1
2
alter user 'root'@'localhost' IDENTIFIED BY '123456';
create user 'root'@'localhost' identified by '123456';

都失败
Operation ALTER USER failed for ‘root‘@’localhost’
Operation CREATE USER failed for ‘root‘@’localhost’

先执行flush privileges

仍然失败,可能是因为用户已经被删除了,再删除一次
drop user ‘root‘@’localhost’;
create user ‘root‘@’localhost’ identified by ‘123456’;
提示密码不符合规则

1
2
3
4
SHOW VARIABLES LIKE 'validate_password%';

set global validate_password.policy=0;
set global validate_password.length=6;
  1. flush 一下

    1
    flush privileges
  2. 重启

    1
    service mysqld restart

记一次重置mysql8密码的操作

https://blogml.top/2020/12/12/mysql-reset-pass/

作者

BoostMerlin

发布于

2020-12-12

更新于

2023-04-16

许可协议