MySQL密码丢了,如何找回?

  1. 首先停止mysql服务
 /etc/init.d/mysqld stop   
  1. 忽略授权表(- -skip-grant-tables) 启动mysql服务
mysqld_safe --skip-grant-tables -user=mysql &
  1. mysql 这时候使用空用户、空密码登录
mysql -uroot -p
  1. 更改root密码
 
select user,host,password from mysql.user;
select user,host,authentication_string from mysql.user;

update mysql.user set password=password('新密码') where user='root' and host='主机名或ip地址'; 
update mysql.user set authentication_string=password('新密码') where user='root' and host='主机名或ip地址'; 

flush privileges;
  1. 退出mysql命令行并杀死当前的mysql进程
ps -ef|grep mysql
/etc/init.d/mysqld stop 或   mysqladmin -uroot -p+密码(刚刚update进去的新密码) shutdown 或 kill mysqld
  1. 重启mysql服务再以正常的方式登录
/etc/init.d/mysqld start

mysql -u用户名 -p新密码
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章