1. 程式人生 > >Linux連線mysql報錯:Access denied for user ‘root’@‘localhost’(using password: YES)的解決方法以及忘記密碼

Linux連線mysql報錯:Access denied for user ‘root’@‘localhost’(using password: YES)的解決方法以及忘記密碼

最近在騰訊雲上買了一伺服器玩想,然後為服務配置好mysql

mysql -uroot -pxxx

要進入發現報錯

Linux連線mysql報錯:Access denied for user ‘root’@‘localhost’(using password: YES)的解決方法

因為第一次遇到這個問題,上網百度了半天,都是一個答案

1.停止mysqld服務
service mysqld stop


進入mysql-bin目錄
./mysqld_safe --skip-grant-tables   在安全模式下執行,並且跳過許可權


然後mysql -u root  直接進入


切換資料庫 use mysql

update user set password=PASSWORD("你的密碼") where User = 'root';


這個方法確實能進來資料庫,但是重新登入的話還是會提示Access的錯誤資訊,應在mysql的配置檔案中加一條skip-grant-tables 這樣就達到了效果, 上面的方法應該是忘記密碼 應該怎麼修改的.