在MySQL登錄時出現Access denied for user 'root'@'localhost' (using password: YES) 拒絕訪問
對於出現拒絕訪問root用戶的解決方案
錯誤1045(28000):用戶'root'@'localhost'(使用密碼:YES)拒絕訪問
首先解析此英文:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES);
解析的地方有兩處:1.Access denied(拒絕訪問);2.using password:NO/YES
一、出現access denied的原因有如下可能:
1)mysql的服務器停止:
若MySQL已經沒有啟動,重啟MySQL服務器:systemctl restart mysqld
2)用戶的端口號或者IP導致:
若用戶的端口號與IP(3306/3307)不一致,打開my.ini文件進行編輯。全部編輯替換為: port=X
3)mysql的配置文件錯誤----my.ini等文件:
my.ini文件誤輸入無效內容,不知道到何處。復制替換該文件;有人已經對my.ini文件進行解釋以及注釋:https://blog.csdn.net/lienfeng6/article/details/78140404
4)root用戶的密碼錯誤(后面解決)
二、出現 using password的原因如下:
不輸入密碼:
錯誤的密碼:
解決方案:
vim /etc/my.cnf文件;
在[mysqld]后添加skip-grant-tables(登錄時跳過權限檢查)
重啟MySQL服務:sudo systemctl restart mysqld
修改密碼
登錄mysql,輸入mysql –uroot –p;直接回車(Enter)
輸入:set password for ‘root’@‘localhost’=password(‘Admin123@qwe’);
如果報:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
輸入:flush privileges;
再次輸入:set password for ‘root’@‘localhost’=password(‘Admin123@qwe’);
為避免麻煩,再次設置遠程訪問
退出:exit
再把my.ini的skip-grant-tables刪除或者注釋掉
重啟MySQL:sudo systemctl restart mysqld
再次連接,成功