Home >Database >Mysql Tutorial >Why Does My MySQL Docker Container Show 'Access Denied' Despite Setting `MYSQL_ROOT_PASSWORD`?
Problem:
You have set MYSQL_ROOT_PASSWORD in your Docker docker-compose.yml file, but when you attempt to connect to the MySQL database, you receive the error "Access denied for user 'root'@'localhost' (using password: YES)."
Cause:
The most likely cause is that you are starting your MySQL container against a preexisting volume that already contains a MySQL database filesystem. In this case, none of the environment variables, including MYSQL_ROOT_PASSWORD, will have any effect.
Solution:
To start from scratch and initialize your container, you need to delete the existing data volume and start the container with a new one. This will wipe out any previous databases in the data volume, so ensure you create a backup if necessary.
Steps:
Additional Information:
This issue is not limited to MySQL docker images. Many official docker images for databases (e.g., PostgreSQL, MongoDB) work in a similar manner. Therefore, if you encounter this problem with other databases, the workaround of deleting the data volume and starting the container from scratch will likely apply.
The above is the detailed content of Why Does My MySQL Docker Container Show 'Access Denied' Despite Setting `MYSQL_ROOT_PASSWORD`?. For more information, please follow other related articles on the PHP Chinese website!