Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLSTATE[HY000] [1045] Access denied for user 'root'@'172.19.0.4' with Docker

I'm currently learning to use Docker on Windows, and I'm following this tutorial. For Docker setup, I'm using Laradock. I'm trying to run mysql apache2 rabbitmq and phpmyadmin containers I did everything the same as in video, but when I try to migrate my tables I get following error:

Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'root'@'172.19.0.4' (using password: YES)

I created empty database in phpmyadmin.

Everything is configured in my projects .env and laradock/.env

My projects env:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=my_database_name
DB_USERNAME=root
DB_PASSWORD=*********

I double checked my password, and it's correct.

My laradock/.env configuration:

MYSQL_VERSION=latest
MYSQL_DATABASE=my_database_name
MYSQL_USER=root
MYSQL_PASSWORD=******
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=******

Docker-compose.yml configuration:

mysql:
  build:
    context: ./mysql
    args:
      - MYSQL_VERSION=${MYSQL_VERSION}
  environment:
    - MYSQL_DATABASE=${MYSQL_DATABASE}
    - MYSQL_USER=${MYSQL_USER}
    - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    - TZ=${WORKSPACE_TIMEZONE}
  volumes:
    - ${DATA_PATH_HOST}/mysql:/var/lib/mysql
    - ${MYSQL_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d
  ports:
    - "${MYSQL_PORT}:3306"
  networks:
    - backend

To ensure all of my containers are working, I enter this command and I get following response:

docker-compose ps

Response from previous command

Root user in my phpmyadmin:

image

like image 760
zlatan Avatar asked Dec 14 '18 15:12

zlatan


Video Answer


1 Answers

Could be related to bind-address accepting only localhost connections. Check out this example of how to use custom mysqld.conf in your mysql container

like image 147
user2087816 Avatar answered Oct 14 '22 15:10

user2087816