Home >Database >Mysql Tutorial >How to Connect to a Docker MySQL Container from Your MacBook's Command Line?

How to Connect to a Docker MySQL Container from Your MacBook's Command Line?

Susan Sarandon
Susan SarandonOriginal
2024-11-10 19:52:03782browse

How to Connect to a Docker MySQL Container from Your MacBook's Command Line?

How to Connect to Docker MySQL Container from Host Command Line

You have a docker container running MySQL and want to connect to it from your MacBook's command line.

Using docker-compose up

Since port 3306 is published on the docker host, you can connect to 127.0.0.1:3306 from the host itself.

Using docker-compose run

When using docker-compose run, the port mapping section of the docker-compose.yml file is ignored by default. To enable it, use the --service-ports option:

docker-compose run --service-ports db

Note on Hostname

By default, the MySQL client attempts to connect using a Unix socket when connecting to localhost. To avoid this, specify the IP address 127.0.0.1:

$ mysql -h 127.0.0.1 -P 3306 -u root

The above is the detailed content of How to Connect to a Docker MySQL Container from Your MacBook's Command Line?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn