7

i am creating mysql docker container using below docker-compose file. Service is created successfully but when i am trying to enter inside the container getting the below error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

docker container exec -it 966 /bin/bash root@96607883960b:/# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) root@96607883960b:/# version: '3.3' services: db: image: mysql:5.7.29 container_name: mysql deploy: replicas: 1 restart_policy: condition: on-failure environment: - MYSQL_USER="testpass" - MYSQL_PASSWORD="testpass" - MYSQL_ROOT_PASSWORD="testpass" ports: - 33060:3306 volumes: - /Users/hello/Work/Volumes/wavolumes/mysql:/var/lib/mysql 

i found many articles didn't help to resolve this issue

is any one having the solution for this issue ?

2
  • Remove the volume it might be caching some old pass and then try, volumes: - /Users/hello/Work/Volumes/wavolumes/mysql:/var/lib/mysql try with out this, if that did not work then try to add command: --default-authentication-plugin=mysql_native_password Commented Jun 28, 2020 at 2:38
  • still same issue . i removed old volume Commented Jun 28, 2020 at 4:13

1 Answer 1

12

Your connection actually works and you can verify it running the following (service should be running already!):

docker-compose exec db sh -c 'mysql -uroot -p${MYSQL_ROOT_PASSWORD}' 

The problem is that you are using the wrong password.

You can see your problem very easily by running docker-compose config. You will see in the output that the double quotes are included as part of the values.

This version should solve your issue:

version: '3.3' services: db: image: mysql:5.7.29 container_name: mysql deploy: replicas: 1 restart_policy: condition: on-failure environment: - MYSQL_USER=testpass - MYSQL_PASSWORD=testpass - MYSQL_ROOT_PASSWORD=testpass ports: - 33060:3306 volumes: - /Users/hello/Work/Volumes/wavolumes/mysql:/var/lib/mysql 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, @Mihai for this simple answer, actually spent almost 4 hrs trying to figure out what was happening with some of my containers not hooking the DB container, had made a simple error in one character on DB password.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.