Problem:
Despite setting the MYSQL_ROOT_PASSWORD environment variable, attempts to access MySQL result in the error: Access denied for user root@localhost (using password: YES).
Resolution:
The issue arises when starting the MySQL container against a pre-existing volume containing a MySQL database filesystem. In such cases, the container skips initialization and environment variables have no effect.
Solution:
Delete the existing data volume:
docker-compose down -v
Recreate the container:
docker-compose up -d
Note: Deleting the volume will erase any existing database data. Create a backup if necessary.
Additional Information:
The above is the detailed content of Why Can't I Access MySQL Even After Setting MYSQL_ROOT_PASSWORD?. For more information, please follow other related articles on the PHP Chinese website!