Windows 10 Pro下Docker部署MySQL登录access denied问题求助
Hey there, let's figure out why you're getting that "access denied" error when trying to log into your MySQL container via the Docker dashboard. I've dealt with this exact issue a few times, so here are the most common fixes to walk through:
常见排查与解决步骤
1. Double-check your login credentials
- When you first spin up the
mysql/mysql-server:latestcontainer, Docker generates a random root password automatically. Grab it by checking the container logs:
Look for a line likedocker logs <your-mysql-container-name>GENERATED ROOT PASSWORD: [random-string]— that's your initial root password. - If you set a custom
MYSQL_ROOT_PASSWORDin yourdocker-compose.yml, make sure the password you're entering matches exactly (watch out for typos, case sensitivity, or special characters that might have been escaped).
2. Allow root access from external addresses
- By default, MySQL's root user might only be allowed to connect from
localhost(inside the container). Since the Docker dashboard is connecting from your Windows host, you'll need to update the user's permissions:- First, jump into the container's MySQL shell:
Enter the correct root password when prompted.docker exec -it <your-mysql-container-name> mysql -uroot -p - Run these SQL commands to grant external access:
TheALTER USER 'root'@'%' IDENTIFIED BY 'your-root-password'; FLUSH PRIVILEGES;%wildcard allows connections from any IP — if you want to restrict it to your host's IP, replace%with that specific address.
- First, jump into the container's MySQL shell:
3. Verify port mapping in docker-compose.yml
- Make sure your compose file maps the container's 3306 port to your Windows host. Here's a quick example of the correct configuration:
services: mysql: image: mysql/mysql-server:latest ports: - "3306:3306" # Maps host port 3306 to container port 3306 environment: MYSQL_ROOT_PASSWORD: your-sec-password-here - If the port mapping is missing or incorrect, the Docker dashboard can't reach the MySQL service even if the container is running fine internally.
4. Reset your Docker dashboard connection
- Sometimes the dashboard saves old or incorrect connection details. Try deleting the existing connection entry, then create a new one with these correct parameters:
- Host:
localhost(or your Windows machine's IP address) - Port: The mapped port from your compose file (usually 3306)
- Username:
root(or a custom user you created) - Password: The valid password for that user
- Host:
5. Confirm the container is actually healthy
- Even if it looks like the container is running, double-check its status and logs for hidden issues:
Make sure the container's status showsdocker psUp(not restarting or exited). If there are restarts, check the latest logs for clues:docker logs --tail 50 <your-mysql-container-name>
内容的提问来源于stack exchange,提问作者Pandiyan MCA
相关产品推荐
相关产品推荐

