版權聲明:本文為博主原創文章,未經博主允許不得轉載。 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;