Mac連線Docker 的Mysql資料庫
因為不想單獨安裝Mysql資料庫,而Docker容器化技術又有先天優勢,所以採用了Docker搭建Mysql資料庫。具體操作如下:
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql/mysql-server
執行Mysql並指定密碼,其中Mysql-server可指定相關版本。
然後採用命令列登陸mysql資料庫:
docker exec -it mysql/mysql-server bash
登陸mysql
mysql -uroot -p
然後採用navicat登陸Mysql測試
首先報錯
1130, "Host 'xxxx' is not allowed to connect to this MySQL server"
通過如下方式解決:
首先查詢select host,user,plugin,authentication_string from mysql.user;
發現root使用者對應的host為localhost。為了後續外部訪問,首先執行下面命令:
use mysql;
update user set host='%' where user='root';
然後在navicat登陸,發現如下錯誤:
Authentication plugin 'caching_sha2_password' cannot be loaded。登陸失敗。
很多使用者在使用Navicat Premium 12連線MySQL資料庫時會出現Authentication plugin 'caching_sha2_password' cannot be loaded的錯誤。
出現這個原因是mysql8 之前的版本中加密規則是mysql_native_password,而在mysql8之後,加密規則是caching_sha2_password, 解決問題方法有兩種,一種是升級navicat驅動,一種是把mysql使用者登入密碼加密規則還原成mysql_native_password.
ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; #修改加密規則 ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; #更新一下使用者的密碼
ALTER USER 'root'@'%' IDENTIFIED BY '123456'
FLUSH PRIVILEGES;
然後navicat就可以正常連線mysql了。