You have a docker container running MySQL and want to connect to it from your MacBook's command line.
Since port 3306 is published on the docker host, you can connect to 127.0.0.1:3306 from the host itself.
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
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!