How to resolve MySQL access denied in Docker Compose

How to resolve MySQL access denied in Docker Compose

Resolving MySQL access denied in Docker compose can be tricky as many things happen behind the scene. It is not always clear what went wrong. Hence, paying a close attention to the output logs could save tremendous amount of time and frustrations.

One of the most encountered errors is an access denied message as follows,

'testuser'@'localhost' and ''

This error usually occurs when you run one runs the docker-compose command and then proceed to change the database password of the docker-compose.yml fille. In that case, if bring down the container and start it again with the docker-compose up -d command, we will encounter an access denied error message since the password will no longer match.

The easiest approach to resolve the issue is to remove the docker container volumes.

For that, we can bring down the container as follows,

$ docker-compose down -v

Otherwise, if the container is already down, we have to find out the volume to delete. For that, we can run docker volume ls. After identifying the volume, just run delete the volume(s) by running,

$ docker volume rm [volume name(s)]


In this article, we addressed how to resolve MySQL access denied in Docker Compose. The error occurs usually when changing the database password in the docker-compose.yml file. To resolve the problem, one can simply delete all the correlated Docker volumes and start fresh from scratch.

Inline/featured images credits