Mac 環(huán)境下, mysql版本
mysql Ver 8.0.13 for osx10.14 on x86_64 (Homebrew)
安裝完成后, 默認(rèn)的是免密登陸, 依據(jù)如下方式更新密碼后出現(xiàn)問題
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
UPDATE mysql.user SET authentication_string = '' WHERE user = 'root' AND host = 'localhost';
修正方法:
- 停止mysql服務(wù)
# 不管有沒有運(yùn)行, 最好執(zhí)行一下
mysql.server stop
- 無密碼啟動MySQL服務(wù)
mysqld_safe --skip-grant-tables --skip-networking &
- 進(jìn)入MySQL
mysql -uroot
- 重新設(shè)置密碼
注意, 8.0.13版本以前形式的設(shè)置密碼無效, 請按如下操作
# 設(shè)置空密碼
UPDATE mysql.user SET authentication_string = '' WHERE user = 'root' AND host = 'localhost';
# 刷新
FLUSH PRIVILEGES;
SELECT host,user, plugin, authentication_string FROM mysql.user;
# 以caching_sha2_password加密密碼并設(shè)置
ALTER user 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '你的密碼';
# 刷新
FLUSH PRIVILEGES;
注意: 有時候會遇到客戶端鏈接不上, 報錯可能如下(筆主是Navicat鏈接報錯)
Failed to Connect to MySQL at 10.211.55.6:3306 with user root
Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image not found
可按下面步驟修改一下密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密碼';
FLUSH PRIVILEGES;
- 退出重新登陸
mysql -uroot -p
# ENTER后正常輸入密碼