问题描述
我已经在Mac上安装了docker.我有在本地计算机(MAC)上运行的MySQL容器.
I have installed docker on my mac. I have MySQL container which is running on my local machine (MAC).
Docker ps命令为我提供以下输出-
Docker ps command is giving me below output -
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b5c50b2d334a test_mysql2 "docker-entrypoint.s…" 2 hours ago Up 2 hours (healthy) 0.0.0.0:32783->3306/tcp test_mysql2_1
我知道将在容器中设置的mysql的用户名和密码.
I know username and password to the mysql which would be setup up in the container.
我想连接到mysql并运行一些查询,但是我无法弄清楚如何连接到它.任何帮助将不胜感激.
I want to connect to mysql and run some queries But I am not able to figure out how to connect to it. Any help will be appreciated.
推荐答案
在 docker ps
的输出中可以看到,端口 32783
(本地计算机)是映射到docker容器内的端口 3306
.如果您使用的是MySQL客户端(例如MySQL Workbench),则应该能够使用ip localhost
和端口 32783
进行连接.如果没有,则应使用 docker exec
,然后在容器内打开一个交互式mysql shell(如mulg0r所评论).
As you can see in the output of docker ps
, the port 32783
(local machine) is mapped to the port 3306
inside the docker container. If you are using a MySQL Client (e.g. MySQL Workbench) you should be able to connect using ip localhost
and port 32783
. If not, you should go with docker exec
and then open a interactive mysql shell inside the container (As mulg0r commented).
这篇关于从主机连接到mysql容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!