docker按照mysql 使用navicat远程登录(阿里云)

安装

  1. 查找Docker Hub上的mysql镜像
[root@izm5ehcc0n8giu3arclxtlz ~]# docker search mysql
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                                                  MySQL is a widely used, open-source relation…   7620                [OK]                
mariadb                                                MariaDB is a community-developed fork of MyS…   2481                [OK]                
mysql/mysql-server                                     Optimized MySQL Server Docker images. Create…   576                                     [OK]
zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       156                                     [OK]
hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          102                                     
zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server wi…   82                                      [OK]
centurylink/mysql                                      Image containing mysql. Optimized to be link…   59                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          48                                      [OK]
centos/mysql-57-centos7                                MySQL 5.7 SQL database server                   45                                      
mysql/mysql-cluster                                    Experimental MySQL Cluster Docker images. Cr…   37                                      
tutum/mysql                                            Base docker image to run a MySQL database se…   31                                      
bitnami/mysql                                          Bitnami MySQL Docker Image                      23                                      [OK]
schickling/mysql-backup-s3                             Backup MySQL to S3 (supports periodic backup…   23                                      [OK]
zabbix/zabbix-proxy-mysql                              Zabbix proxy with MySQL database support        18                                      [OK]
linuxserver/mysql                                      A Mysql container, brought to you by LinuxSe…   17                                      
centos/mysql-56-centos7                                MySQL 5.6 SQL database server                   12                                      
mysql/mysql-router                                     MySQL Router provides transparent routing be…   8                                       
circleci/mysql                                         MySQL is a widely used, open-source relation…   8                                       
openshift/mysql-55-centos7                             DEPRECATED: A Centos7 based MySQL v5.5 image…   6                                       
dsteinkopf/backup-all-mysql                            backup all DBs in a mysql server                5                                       [OK]
jelastic/mysql                                         An image of the MySQL database server mainta…   1                                       
openzipkin/zipkin-mysql                                Mirror of https://quay.io/repository/openzip…   1                                       
cloudposse/mysql                                       Improved `mysql` service with support for `m…   0                                       [OK]
ansibleplaybookbundle/mysql-apb                        An APB which deploys RHSCL MySQL                0                                       [OK]
cloudfoundry/cf-mysql-ci                               Image used in CI of cf-mysql-release            0                                       
  1. 拉取官方镜像
[root@izm5ehcc0n8giu3arclxtlz ~]# docker pull mysql:5.6

等待下载完成后,我们就可以在本地镜像列表里查到REPOSITORY为mysql,标签为5.6的镜像。

[root@izm5ehcc0n8giu3arclxtlz ~]# docker images |grep mysql
mysql                                           5.6                 27e29668a08a        35 hours ago        256MB
  1. 运行容器
[root@izm5ehcc0n8giu3arclxtlz ~]# docker run --name mysql01 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
21cb89213c93d805c5bacf1028a0da7b5c5852761ba81327e6b99bb3ea89930e

命令说明:

  • -p 3306:3306:将容器的 3306 端口映射到主机的 3306 端口。

  • -v -v $PWD/conf:/etc/mysql/conf.d:将主机当前目录下的 conf/my.cnf 挂载到容器的 /etc/mysql/my.cnf。

  • -v $PWD/logs:/logs:将主机当前目录下的 logs 目录挂载到容器的 /logs。

  • -v $PWD/data:/var/lib/mysql :将主机当前目录下的data目录挂载到容器的 /var/lib/mysql 。

  • -e MYSQL_ROOT_PASSWORD=123456:初始化 root 用户的密码。

  • -d:成功启动容器后输出容器的完整ID,例如上图21cb89213c93d80

  • 最后一个mysql指的是mysql镜像名字

  1. 查看容器启动情况
[root@izm5ehcc0n8giu3arclxtlz ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
ea88bec5b27c        mysql:5.6           "docker-entrypoint.s…"   5 hours ago         Up 5 hours          0.0.0.0:3306->3306/tcp   mysql01

上图可以看到容器的简写ID,容器的源镜像,创建时间,状态,端口映射信息,容器名字等。

  1. 容器内登录mysql

进入镜像中的mysql

[root@izm5ehcc0n8giu3arclxtlz ~]# docker exec -ti 容器ID或容器名称(比如21cb89213c93d805或者mysql01) /bin/bash
root@ea88bec5b27c:/# 

登录mysql

root@ea88bec5b27c:/# mysql -u root -p
Enter password: 

输入密码后登入mysql

客户端登录

终端登录mysql后,执行下面命令允许远程登录 ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
使用navicat连接mysql,
docker按照mysql 使用navicat远程登录(阿里云)_第1张图片
一直提示:
Can't connect to MySQL server on 'xx.xx.xx.xx' (60 "Operation timed out")
在网上查了下,阿里云服务器在控制台也有防火墙的设置,必须也要在控制台开启才行
docker按照mysql 使用navicat远程登录(阿里云)_第2张图片
添加支持3306端口,之后重启服务器。
再次使用navicat连接,成功了。。。。。。。

你可能感兴趣的:(Linux,mysql)