"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > MacBook Connect Docker MySQL Container Command Line Guide

MacBook Connect Docker MySQL Container Command Line Guide

Posted on 2025-04-16
Browse:888

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
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3