You desire to establish a connection to a MySQL instance running within a Docker container from your host machine. Despite efforts, your attempts have been unsuccessful.
Docker Configuration
Your Dockerfile configures:
Host Connectivity Issues
Despite a successful container startup and MySQL accessibility within the container, you encounter an error when attempting to connect from the host:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Solution: Specify Host, Port, and Protocol
To establish a connection from the host to the MySQL container, you must specify the following parameters in the mysql command:
The corrected command should be:
mysql -h localhost -P 12345 --protocol=tcp -u root
The above is the detailed content of How Can I Connect to a MySQL Docker Container from My Host Machine?. For more information, please follow other related articles on the PHP Chinese website!