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

How to Connect to a MySQL Container from Your Host Machine's Command Line?

Linda Hamilton
Release: 2024-11-19 08:41:02
Original
933 people have browsed it

How to Connect to a MySQL Container from Your Host Machine's Command Line?

Connecting to MySQL Container from Host Machine

You have a MySQL container running in Docker and want to establish a connection to it from your MacBook's command line mysql client without using Docker commands.

Docker-Compose Up

If you're using docker-compose up, connect to the container using 127.0.0.1:3306, as the host port 3306 is published.

Docker-Compose Run

When using docker-compose run, the port mapping section in the docker-compose.yml file is not considered. To enable it, add the --service-ports option:

docker-compose run --service-ports db
Copy after login

Additional Note

By default, the mysql client attempts to use a unix socket when connecting to localhost. Therefore, specify the IP address 127.0.0.1 explicitly:

mysql -h 127.0.0.1 -P 3306 -u root
Copy after login

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

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template