I’m having trouble connecting to a MySQL server running in a Docker container on my Mac from a Windows PC on the same network. Here’s what I’ve done:
- Set up MySQL in a Docker container
- Created a user with all privileges
- Confirmed the user exists and bind_address is 0.0.0.0
I can connect locally on the Mac using:
mysql -u user1 -h localhost -P 3307 -p'mypass'
But when I try from my Windows PC:
mysql -u user1 -h 10.0.0.173 -P 3307 -p'mypass'
I get:
ERROR 1045 (28000): Access denied for user 'user1'@'192.168.65.1' (using password: YES)
The logs show the connection attempt but deny access. I’ve tried different ports and IP addresses, but no luck. Is this a Docker networking issue? How can I troubleshoot this?
I’ve dealt with this exact issue before. The problem likely lies in your MySQL configuration. Make sure your my.cnf file includes ‘bind-address = 0.0.0.0’ to allow connections from any IP. Also, verify that your Docker container is exposing port 3307 correctly. You might need to adjust your Docker run command to include ‘-p 3307:3306’ if you haven’t already. Lastly, check that your Windows firewall isn’t blocking incoming MySQL connections. These steps should resolve your remote access problem.
hey alex, sounds like a pain! have u checked if ur docker container is exposing the port correctly? try running ‘docker ps’ to see if 3307 is listed. also, double-check the firewall on both machines. sometimes it blocks mysql traffic. good luck mate!
I’ve run into this frustrating issue too. One thing that worked for me was double-checking the user privileges. Sometimes, even if you think you’ve granted all privileges, there might be a hiccup. Try logging into MySQL on your Mac and running:
SHOW GRANTS FOR ‘user1’@‘%’;
Make sure it shows GRANT ALL PRIVILEGES ON . TO ‘user1’@‘%’.
If that looks good, another thing to check is your Docker network setup. Sometimes the default bridge network can cause issues. Try creating a custom network:
docker network create mynetwork
docker run --network mynetwork --name mysql-container -e MYSQL_ROOT_PASSWORD=mypass -p 3307:3306 -d mysql
This explicitly maps the container’s 3306 to your host’s 3307. Hope this helps you troubleshoot!
Recently I encountered a similar issue with Docker and remote MySQL access. I found that ensuring the container port is correctly published is crucial; for instance, using the -p option properly helps direct external connections to the MySQL service inside Docker. On my system, I had to examine Docker’s network configuration and adjust firewall settings to enable incoming traffic on the designated port. It also helped to confirm that MySQL was set up with permissions allowing connections from any host. Checking these aspects helped me isolate and resolve the connection problem.