When attempting to connect to a MySQL instance running within a Docker container from the host machine, you may encounter the error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
To resolve this issue and connect successfully, follow these steps:
mysql -h localhost -P <port> --protocol=tcp -u root
Replace
With these modifications, you should be able to successfully connect to the MySQL instance in the Docker container from your host machine. Remember to replace localhost in the connection command with the IP address or hostname of the host machine.
The above is the detailed content of How Do I Connect to a MySQL Docker Container from My Host Machine?. For more information, please follow other related articles on the PHP Chinese website!