Docker-MySQL
使用官方镜像快速启动一个MySQL Server实例(MySQL8)
如下
FengZhen$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=123456 -p 53306:3306 -d mysql:latest 906b498c04db2bfe57349760941222ca063c3b169885969c95e5656a55c3a6ff FengZhen$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 906b498c04db mysql:latest "docker-entrypoint.s…" 9 seconds ago Up 12 seconds 0.0.0.0:53306->3306/tcp mysql
进入MySQL
FengZhen$ docker exec -it 906b498c04db mysql -u root -p mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec)
在宿主主机进入MySQL
FengZhen$ mysql -u root -p -h192.168.1.102 -P53306
使用Navicat连接失败
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 BY 'password' PASSWORD EXPIRE NEVER; #修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #更新一下用户的密码
3. 刷新权限并重置密码
FLUSH PRIVILEGES; #刷新权限
MySQL5.7.4
启动MySQL容器
FengZhen$ docker run -it --name mysql5.7.4 -p 53307:3306 -e MYSQL_ROOT_PASSWORD=123456 daocloud.io/library/mysql:5.7.4
进入MySQL,修改权限
FengZhen$ docker exec -it mysql5.7.4 mysql -u root -p mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
本地连接测试
FengZhen$ mysql -u root -p -h192.168.1.102 -P53307
使用Navicat连接。