Linux 破解mysql密码


mysql忘记密码怎么办

[root@master ~]# mysql -uroot -pHuawei123123$
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@master ~]# 

1.更改配置文件

在[mysqld]下增加一条 skip-grant-tables

重启mysql
systemctl restart mysqld

2.进入mysql

[root@master ~]# mysql -uroot
选择数据库
use mysql
显示所有表
show tables;
查看user表
select * from user\G


可以看到密码在最下面

3.更新数据库信息

update user set authentication_string=password('Passwd123$') where Host='localhost' and User='root';

4.删除skip-grant-tables并重启服务


systemctl restart mysqld

5.用新密码登录


mysql -uroot -pPasswd123$

成功