MySQL数据库root密码丢失问题

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_44297303/article/details/96605027

问题:丢失超户密码,进不去数据库:

#./mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

在这里插入图片描述

强制停掉数据库

# ps -ef | grep mysql

在这里插入图片描述

# kill -9 44184 43251

加跳过权限表参数,重启数据库

  • 加 --skip-grant-tables参数,可跳过权限表
# ./mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &
# ./mysql		#不用密码,也能进入数据库

在这里插入图片描述

给root用户设置新密码并刷新权限

root@localhost [(none)]>use mysql;
root@localhost [mysql]>update user set authentication_string=password('root') where user='root';
root@localhost [mysql]>flush privileges;
  • password(‘密码’),第一个root才是密码
    在这里插入图片描述

将之前的mysql进程kill掉,然后重新登陆即可

# ./mysqld_safe --defaults-file=/etc/my.cnf &
# ./mysql -uroot -proot

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44297303/article/details/96605027