skip to Main Content

I have a local Symfony Project where I want to execute a Repository Function inside the code. The Problem is that I get an "Access Denied" Error. The credentials are correct because I can log into the adminer that also runs inside Docker.

System: MacOS
Docker-V: 4.24.2
Symfony-V: 6.4.3

Error-Message:

An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: YES)

my docker-compose.yml:

version: "3.8"
services:
    mysql:
        image: mariadb:10.8.3
        platform: linux/arm64/v8
        command: --default-authentication-plugin=mysql_native_password
        environment:
            MYSQL_ROOT_PASSWORD: root
            MYSQL_USER: root
        ports:
            - "3306:3306"
    adminer:
        image: adminer
        ports:
            - "8080:8080"

Database URL in the .env:

DATABASE_URL="mysql://root:[email protected]:3306/symfony6-test?serverVersion=10.8.3-MariaDB&charset=utf8mb4"
  • I tried replacing 127.0.0.1 with localhost
  • I looked at the Docker Container config with docker inspect. With the docker inspect it shows a different IP Address: 172.19.0.3, but when I tried to use this address it gives me a "Network unreachable" Error
  • I reset docker to factory mode, but this didn’t fix the problem

2

Answers


  1. Chosen as BEST ANSWER

    So the Problem was that another mysql Service was running locally which i didnt even know was there. It had to be up for months without me noticing.

    So if you have the same Problem make sure, that there is no other mysql service running.


  2. Hello try this configs this is what I use for symfony:

    database:
            image: mariadb:10.6
            ports:
                - "3307:3306"
            environment:
                - MYSQL_ROOT_PASSWORD=dbpassword
                - MYSQL_USER=myuser
                - MYSQL_PASSWORD=maypassword
                - MYSQL_DATABASE=mydb
            volumes:
                - ./var/database:/var/lib/mysql:delegated
    

    also it would be useful if you post your php image configuration from docker-compose file.
    If you want to connect to the db configure the port to 3307.

    $ mysql -u myuser -P 3307 mydb -p
    

    normally it should work on localhost if it didnt work try :

    $ mysql -u myuser -h 127.0.0.1 -P 3307 mydb -p
    

    of course change the variable names of user, pass and database name as you see fit.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search