MySQL 丟失密碼問題

來源:互聯網
上載者:User

重設MySQL密碼:

停止MySQL服務,使用skip-grant-tables參數啟動   

service mysqld stop;
mysqld_safe --skip-grant-tables --user=mysql&

  此時無需授權就可以進入到MySQL命令列   
mysql>UPDATE mysql.user SET Password=PASSWORD('...') WHERE User='...' AND Host= '...';FLUSH PRIVILEGES;

  以上的操作還是會有一些紕漏:
  重設密碼這個時間段內,任何人都能串連MySQL(除非資料庫伺服器屏蔽了外網訪問);
  推薦方式:   
shell>service mysqld stop;
//將UPDATE mysql.user SET Password=PASSWORD('...') WHERE User='...' AND Host= '...';FLUSH PRIVILEGES;這句SQL語句寫入到mysql有許可權讀取的目錄;
mysql>mysqld_safe --init-file=/path/to/init/file --user=mysql &
//最後刪除該檔案,免得密碼泄露;

  避免重啟兩次MySQL!!!
  值得一提的是:在MySQL5.6中,使用mysql_config_editor加密.mylogin.cnf 進行登入;只要該檔案存在,就不用考慮丟失密碼的問題啦!

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.