CentOS7下使用docker远程连接windows10中的mysql
-
拉取镜像 (windows中mysql的版本号)
[root@hadoop ~]# docker pull mysql:8.0.27
-
创建并启动容器
[root@hadoop ~]# docker run -p 3306:3306 --name windshady -e MYSQL_ROOT_PASSWORD=197300 -d mysql:8.0.27 4b0d29f121a958c96456309cf107b6dd7f391558ea6bfa9e53cf6ad453405815
-
查看容器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
-
进入容器
[root@hadoop ~]# docker exec -it 4b0d29f121a9 bash
-
连接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
连接成功