原因
在使用 docker-compose
安裝 MySQL 8 (mysql/mysql-server:8
) 後,要連線登入時,會出現下列訊息
Authentication plugin ‘caching_sha2_password’ cannot be loaded
version: '3.9'
networks:
local-proxy-network:
driver: bridge
services:
mysql:
container_name: local_mysql
image: 'mysql/mysql-server:8'
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: "password"
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: "kj"
MYSQL_USER: "kj"
MYSQL_PASSWORD: "kj"
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- './storage/docker/mysql/:/var/lib/mysql'
networks:
- local-proxy-network
restart: always
這個是 MySQL 升級至 8 後有修改密碼驗證方式導致的問題
版本 | 驗證方式 |
---|---|
MySQL 8 | caching_sha2_password |
MySQL 5.7 | mysql_native_password |
解決方式 1:修改連線方式
使用 Terminal 連線到 MySQL 後將連線方式修改為 mysql_native_password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your-password';
解決方式 2:修改 my.cnf 設定檔案
編輯 MySQL 8 的 my.cnf
檔案
vim my.cnf
設定預設密碼驗證方式為 mysql_native_password
[mysqld]
default_authentication_plugin=mysql_native_password
Reference
- MySQL :: MySQL 8.0 Reference Manual :: 2.11.4 Changes in MySQL 8.0
- 解决MAC+ MySQL 8 错误:Authentication plugin ‘caching_sha2_password’ cannot be loaded - 简书
Donate KJ 贊助作者喝咖啡
如果這篇文章對你有幫助的話,可以透過下面支付方式贊助作者喝咖啡,如果有什麼建議或想說的話可以贊助並留言給我
If this article has been helpful to you, you can support the author by treating them to a coffee through the payment options below. If you have any suggestions or comments, feel free to sponsor and leave a message for me!
方式 Method | 贊助 Donate |
PayPal | https://paypal.me/kejyun |
綠界 ECPay | https://p.ecpay.com.tw/AC218F1 |
歐付寶 OPay | https://payment.opay.tw/Broadcaster/Donate/BD2BD896029F2155041C8C8FAED3A6F8 |