Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

foxdevuz's avatar

Cannot connect to mysql

Hello, I am trying to use laravel inside docker and mysql but I got this

SQLSTATE[HY000] [1045] Access denied for user 'root'@'172.26.0.3' (using password: YES)

I can not even connect to mysql with mysql -u root -p inside docker image

abdullajonov@arch /s/h/W/G/database (main) [1]> docker exec -it mysql8 bash
bash-5.1# mysql -u root 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
bash-5.1# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
bash-5.1# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
bash-5.1# 

Here's the docker-compose.yml

    mysql:
      image: mysql:8.0
      container_name: mysql8
      restart: always
      environment:
        MYSQL_DATABASE: database
        MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
        MYSQL_ROOT_HOST: '%'
      volumes:
        - mysql_data:/var/lib/mysql
      networks:
        - app-network
      command: --default-authentication-plugin=caching_sha2_password

and .env

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=root
DB_PASSWORD=

how can I fix it?

0 likes
0 replies

Please or to participate in this conversation.