Home > Database > Mysql Tutorial > Why Can't I Access MySQL Even After Setting MYSQL_ROOT_PASSWORD?

Why Can't I Access MySQL Even After Setting MYSQL_ROOT_PASSWORD?

DDD
Release: 2024-12-01 16:00:14
Original
263 people have browsed it

Why Can't I Access MySQL Even After Setting MYSQL_ROOT_PASSWORD?

How to Access MySQL if MYSQL_ROOT_PASSWORD is Set

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:

  1. Delete the existing data volume:

    docker-compose down -v
    Copy after login
  2. Recreate the container:

    docker-compose up -d
    Copy after login

Note: Deleting the volume will erase any existing database data. Create a backup if necessary.

Additional Information:

  • Official MySQL Docker image documentation states: "none of the variables below will have any effect if you start the container with a data directory that already contains a database."
  • The same issue can occur with other official database Docker images (e.g., Postgres, MongoDB).
  • If converting to a bind mount, you will need to manually delete all its contents to force initialization.

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template