MySQL_ROOT_PASSWORD Is Set, But Access Denied for User 'root'@'localhost' (using Password: YES)
In dockerized MySQL environments, setting the MYSQL_ROOT_PASSWORD environment variable is not sufficient to ensure access to the database. This is because the image will not initialize a new database if the db_data volume already contains an existing installation.
Troubleshooting:
Delete the db_data volume to force initialization:
Convert to a bind mount if desired:
After initializing the database, you can convert the volume to a bind mount by changing the volumes section in docker-compose.yml to:
volumes: - /host/path/to/db_data:/var/lib/mysql
Check for other potential issues:
The above is the detailed content of Why Does 'Access Denied' Occur for the MySQL Root User Even When MYSQL_ROOT_PASSWORD Is Set in Docker?. For more information, please follow other related articles on the PHP Chinese website!