Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql-docker-container - ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

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 ?

like image 843
Madhu Avatar asked Jun 28 '20 02:06

Madhu


People also ask

What is MySQL error 1045 (28000)?

The error is ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES). The error appears upon logging attempt to MySQL command console. The following is the execution of the logging attempt to MySQL Command console showing the error message :

Why can't I Access MySQL database remotely using root account?

Unable to access MySQL database remotely using root account. Any attempt to access MySQL database will result in error: The above MySQL error message is a default behavior of the MySQL server to disallow a Root user to connect remotely as by default the Root user is allowed to connect to MySQL server on from localhost that is 127.0.0.1.

How to resolve the'Access Denied'issue in Docker?

Another possible resolution to the 'access denied' issue is provided in this issue: #241. In short, add MYSQL_ROOT_HOST=% as an environment variable. Sorry, something went wrong. I was facing this issue, not related to Docker, but found it while using docker-compose with multiple mysql instances on localhost:

How do I find the MySQL connection id in Docker?

docker exec -it <CONTAINER_ID> mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 360 Server version: 8.0.21 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates.


1 Answers

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
like image 84
Mihai Avatar answered Sep 30 '22 13:09

Mihai