MySQL mysqld_safe登入更改使用者密碼和解決本地localhost不能登入
阿新 • • 發佈:2019-02-05
忘記MySQL密碼或者本地lcoalhost,root使用者無法登入時。可用以下方法無密碼登入
1 /etc/init.d/mysqld stop 關閉mysqld服務 (可以直接killall mysqld)
2 mysqld_safe --skip-grant-tables &
3 mysql 登入
4 更改mysql使用者密碼:update mysql.user set password=password("123456") where user=root and host=localhost;
5 flush privileges;ss
6 quit退出
7 重啟mysqld服務 /etc/init.d/mysqld restart
8 測試修改後密碼登入
本地lcoalhost,root使用者無法登入
1 /etc/init.d/mysqld stop 關閉mysqld服務 (可以直接killall mysqld)
2 mysqld_safe --skip-grant-tables &
3 mysql 登入
4 檢視mysql.user表root使用者host欄位是否有localhost值。如果沒有需加上5 退出重啟mysqld服務
6 測試登入,如果還無法登入則有可能沒有授權localhost登入
7 使用mysql -uroot -h127.0.0.1 -p登入並授權localhost本地root登入
8 測試登入