Docker安装Mysql5.7+远程访问

第一步:安装Docker

请查看: CentOS 7安装Docker

第二步:下载mysql5.7镜像

# docker pull mysql:5.7

查看镜像

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 ae6b78bedf88        5 weeks ago         372MB
mysql               latest              f991c20cb508        5 weeks ago         485MB

这里使用的是5.7,最新版本由于密码规则我的navicat只能连接上root用户远程,所以改为mysql57

第三步:运行容器

#  docker run -p 3308:3306 --name mymysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/mysql_data -e MYSQL_ROOT_PASSWORD=Qabc_123 -d mysql:5.7

我这里映射本地的3308端口,注意需要再防火墙中开启3308,如果是云服务器,需要在安全组中放行端口。

防火墙开启3308端口:

# firewall-cmd --zone=public --add-port=3308/tcp --permanent(--permanent永久生效)
# 重新载入
# firewall-cmd --reload

或者干脆直接关闭防火墙

# systemctl stop firewalld

第四步,进入容器,开启远程访问

查看容器

# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
5524ddca12c1        mysql:5.7           "docker-entrypoint..."   16 hours ago        Up 16 hours         33060/tcp, 0.0.0.0:3308->3306/tcp   mymysql

进入容器

# docker exec -it mymysql bash

登陆mysql

root@5524ddca12c1:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

创建数据库

mysql> create database hdl_crm;

创建用户并授权

mysql> grant all privileges on hdl_crm.* to crm@"%" identified by "password" with grant option;

刷新权限

mysql> flush privileges;

第五步,工具连接

使用navicat链接mysql

 

至此,大功告成。

闲暇之余,记录一下过程。

 

参考文章:Docker安装mysql 配置远程登录

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农小何

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值