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
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