如何在docker的mysql中建立远程连接

开启docker

docker ps# 查看正在运行的docker
docker ps -a查看所有的docker
docker start 容器id #启动容器可以运行

进入容器中

docker exec -it id /bin/bash

开启mysql服务

mysql -h ip -P 端口号 -u 账号 -p密码

进入mysql

mysql> select host,user,plugin,authentication_string from mysql.user; 

host为 % 表示不限制ip localhost表示本机使用 plugin非mysql_native_password 则需要修改密码

修改sql连接权限

    #第一步grant all privileges on *.* to root@"%" identified by "password" with grant option;#第二步flush privileges; 

host为 % 表示不限制ip localhost表示本机使用 plugin非mysql_native_password 则需要修改密码

关闭服务重启服务

   service restart mysql