Home > Database > Mysql Tutorial > Why Does My MySQL Docker Container Show 'Access Denied' Despite Setting `MYSQL_ROOT_PASSWORD`?

Why Does My MySQL Docker Container Show 'Access Denied' Despite Setting `MYSQL_ROOT_PASSWORD`?

Mary-Kate Olsen
Release: 2024-12-05 08:03:10
Original
470 people have browsed it

Why Does My MySQL Docker Container Show

MYSQL_ROOT_PASSWORD is Set, But I'm Getting "Access Denied" When Trying to Access MySQL DB in a Docker Container

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:

  1. Use docker-compose down -v to delete the existing data volume.
  2. Use docker-compose up -d to start the container with a new data volume.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template