数据库:mysql数据库root密码破解

1、首先进入mysql数据库的单用户模式

vim /etc/my.cnf
[mysqld]下一行插入内容
[mysqld]
skip-grant-tables 
#数据库的单用户模式
skip-networking  
#MySQL8.0不需要,添加完成后保存退出

2、重启mysqld服务然后登录直接登录数据库不需要输入密码回车即可进入。

3、 进入后清空原来的root密码添加新密码即可

update mysql.user set authentication_string='' where user='root' and host='localhost';
#表示清空mysql库中的user表中authentication_string字段,当用户是root且host是localhost时
flush privileges;
#注意刷新后生效
quit
#退出数据库
vim /etc/my.cnf
#将单用户的内容关闭重启mysql数据库
mysql  -uroot -p
#直接登录然后设置自己想要的root密码即可
alter user root@'localhost'  identified by '新密码';

猜你喜欢

转载自blog.csdn.net/weixin_67287151/article/details/129719206