1、拉取mysql镜像

docker pull mysql:5.6

2、运行mysql的镜像生成一个正在运行的容器,可以通过docker contain ls得到容器的id信息

docker run -dit -p 3306:3306 mysql:5.6 bash  # 会返回容器的id,赋值前5、6位就可以了,改为5.7也一样
docker exec -it container_id bash # 使用上面复制的容器ID前5、6位,进入容器
# 使用uname -a查看系统为ubuntu系统
# 查看mysql的状态
service mysql status
# 启动mysql
service mysql start
# 进入mysql客户端
mysql
# 添加远程访问权限,在下面语句中的*和%号的说明,不懂得话,请查看后面的参考博客
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
# 在另一台电脑上使用root,123456进行登录mysql可以成功进入,需要注意防火墙的开关,我电脑默认是关闭的
mysql> flush privileges;

在自己搭建的时候,没有进行mysql远程访问权限设置,在另一台电脑上登录的时候报错,退出容器使用ctrl + D退出

host 'xxx' is not allowed to connect to mysql server

然后就参考了博客:https://www.cnblogs.com/jesu/p/5650699.html

 

相关文章:

  • 2021-12-15
  • 2021-12-12
  • 2022-12-23
  • 2021-09-24
  • 2022-01-04
  • 2021-12-15
  • 2021-09-30
  • 2021-12-05
猜你喜欢
  • 2021-06-09
  • 2021-07-18
  • 2021-08-11
  • 2021-10-13
  • 2021-10-01
  • 2019-03-08
  • 2022-12-23
相关资源
相似解决方案