Docker: Permission Denied to Local MySQL Volume

Permission error with Docker-compose and MYSQL

Your container cannot read the file dump.sql in /docker-entrypoint-initdb.d/ which mount to the directory on your host ./mysql. chmod 777 ./mysql to allow the read.

MYSQL_ROOT_PASSWORD is set but getting Access denied for user 'root'@'localhost' (using password: YES) in docker container

The below description is specifically for MySQL but many other official db docker images (postgres, mongodb....) work a similar way. Hence the symptom (i.e. access denied with configured credentials) and workaround (i.e. delete the data volume to start initialization from scratch) are the same.


Taking for granted you have shown your entire start log, it appears you started your mysql container against a pre-existing db_data volume already containing a mysql database filesystem.

In this case, absolutely nothing will be initialized on container start and environment variables are useless. Quoting the official image documentation in the "Environment Variables" section:

Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.

If you want your instance to be initialized, you have to start from scratch. It is quite easy to do with docker compose when using a named volume like in your case. Warning: this will permanently delete the contents in your db_data volume, wiping out any previous database you had there. Create a backup first if you need to keep the contents.

docker-compose down -v
docker-compose up -d

If you ever convert to a bind mount, you will have to delete all it's content yourself (i.e. rm -rf /path/to/bind/mount/*)

Docker container can't connect to its mysql server (ACCESS DENIED)

seems like you have to change the password and run the command with existing volume, so it's not going to set new password as the default behaviour of Docker MySQL image.

You have two option

  • try to remvoe volume and run the container
docker volume rm volume1 && docker run -it --rm -v volume1:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=12345 -e MYSQL_DATABASE=users mysql:latest --default-authentication-plugin=mysql_native_password
  • try to run with an old password that was set during volume creation

MySQL with docker Access denied

The article you have followed is outed and also running container and the change password is not the proper way when working in the container. With Offical image, you can set using environment variable.

use below command and further details you can find on Mysql Docker hub.

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mypass -d mysql

then try to connect

docker exec -it some-mysql bash -c "mysql -u root -pmypass"


Related Topics



Leave a reply



Submit