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新密碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章