centos7下使用docker远程连接宿主机windows10中的mysql

CentOS7下使用docker远程连接windows10中的mysql

  1. 拉取镜像 (windows中mysql的版本号)

    [root@hadoop ~]# docker pull mysql:8.0.27 
  2. 创建并启动容器

    [root@hadoop ~]# docker run -p 3306:3306 --name windshady -e MYSQL_ROOT_PASSWORD=197300 -d mysql:8.0.27
    4b0d29f121a958c96456309cf107b6dd7f391558ea6bfa9e53cf6ad453405815
  3. 查看容器id 4b0d29f121a9

    [root@hadoop ~]# docker ps
    CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS              PORTS                                                  NAMES
    4b0d29f121a9   mysql:8.0.27   "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   windshady
  4. 进入容器

    [root@hadoop ~]# docker exec -it 4b0d29f121a9 bash
  5. 连接windows中的mysql (输入密码时不显示,不用管它)

    root@4b0d29f121a9:/# mysql -h192.168.19.1 -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 253
    Server version: 8.0.27 MySQL Community Server - GPL
    ​
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    ​
    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.

         可能遇到的问题:

           1.保证虚拟机和宿主机都关闭防火墙

           2.虚拟机linux可以ping通windows,我的是ipv4,192.168.19.1即远程连接windows中的-h

[root@hadoop ~]# ping 192.168.19.1
PING 192.168.19.1 (192.168.19.1) 56(84) bytes of data.
64 bytes from 192.168.19.1: icmp_seq=1 ttl=128 time=2.15 ms
64 bytes from 192.168.19.1: icmp_seq=2 ttl=128 time=0.955 ms
64 bytes from 192.168.19.1: icmp_seq=3 ttl=128 time=0.742 ms
64 bytes from 192.168.19.1: icmp_seq=4 ttl=128 time=1.91 ms
64 bytes from 192.168.19.1: icmp_seq=5 ttl=128 time=1.15 ms
64 bytes from 192.168.19.1: icmp_seq=6 ttl=128 time=0.800 ms

         连接成功      

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值