解決linux-mysql 登錄時,報異常:Access denied for user 'root'@'localhost'


版權聲明:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/hhj724/article/details/73277506

解決linux-mysql 登錄時,報異常:Access denied for user 'root'@'localhost'

第一步:停服務

/etc/init.d/mysql stop

或者

service mysqld stop


第二步:跳過密碼驗證
執行命令行:
# /usr/bin/mysqld_safe --skip-grant-tables
報:
151104 09:07:56 mysqld_safe Logging to '/var/lib/mysql/iZ23dq2wm0jZ.err'.
151104 09:07:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

第三步:無密碼登錄
執行命令行:
mysql -u root 

第四步:授權

mysql>

grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;
關鍵詞解釋:
root'@'localhost:是用戶
root:是密碼

問題一:發現無密碼條件下,沒有授權的寫權限

The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
解決方法:

mysql> set global read_only=0;//(關掉新主庫的只讀屬性)
mysql>flush privileges;

再次執行第四步授權語句:grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;

mysql>set global read_only=1;//(讀寫屬性)
mysql>flush privileges;

(注意刷新是必須項)

第五步:重啟數據庫
/etc/init.d/mysql restart

或者
service mysql restart


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM