0

When i try to create database for this educational project I get this error: Could not create database for connection named default An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied 'root'@'localhost'

What i did (followed authors guidelines):

  • installed symfony packages
  • installed and run docker
  • all needed files are preconfigured from the project (docker-compose.yml, .env, doctrine.yaml)

I tried in 2 ways create DB:

1st WAY

# .env
DATABASE_URL="mysql://root:root@127.0.0.1:3306/symf6-hands-on?serverVersion=mariadb-10.8.3&charset=utf8mb4"
# doctrine.yaml 
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        server_version: '10.8.3'

so i tried multiple server versions here:

# .env i tried different server versions to run with
DATABASE_URL="mysql://root:root@127.0.0.1:3306/symf6-hands-on?serverVersion=mariadb-10.8.3&charset=utf8mb4"
# or this 
DATABASE_URL="mysql://root:root@127.0.0.1:3306/symf6-hands-on?serverVersion=10.8.3-MariaDB-1:10.8.3+maria~jammy&charset=utf8mb4"
# or this 
DATABASE_URL="mysql://root:root@127.0.0.1:3306/symf6-hands-on?serverVersion=10.8.3-MariaDB-1:10.8.3+maria~jammy&charset=utf8mb4&sslmode=disable"

2nd WAY

# doctrine.yaml 
    dbal:
        #url: '%env(resolve:DATABASE_URL)%'
        server_version: '10.8.3'
        driver: pdo_mysql
        host: 127.0.0.1
        port: 3306
        dbname: symf6-hands-on
        user: root
        password: root

Logged in docker to check the version

$ docker exec -it symfony6-hands-on-mysql-1 mysql -u root -p

 MariaDB [(none)]> select version();
 +-------------------------------------+
 | version()                           |
 +-------------------------------------+
 | 10.8.3-MariaDB-1:10.8.3+maria~jammy |
 +-------------------------------------+

In both ways I used these docker configs with next commands: symfony console doctrine:database:create or bin/console doctrine:database:create

# docker-compose.yml
  mysql:
    external_links:
      - "host.docker.internal:localhost"
    image: mariadb:10.8.3
    # Uncomment below when on Mac M1
    platform: linux/arm64/v8
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - 3306:3306

configuration of environment Mac M1 Ventura 13.1 with php bin/console about:

-------------------- --------------------------------- 
  Symfony                                               
 -------------------- --------------------------------- 
  Version              6.1.12          ...                
 -------------------- --------------------------------- 
  Kernel                                                
 -------------------- --------------------------------- 
  Type                 App\Kernel                       
  Environment          dev                              
  Debug                true                             
  Charset              UTF-8           ...              
 -------------------- --------------------------------- 
  PHP                                                   
 -------------------- --------------------------------- 
  Version              8.2.1                            
  Architecture         64 bits                          
  Intl locale          en_US_POSIX                      
  Timezone             UTC (2023-02-16T09:50:54+00:00)  
  OPcache              true                             
  APCu                 false                            
  Xdebug               false                            
 -------------------- --------------------------------- 

I already tried solutions from other questions but none of them worked thanks

UPDATE -------------------------------------

I tried to grand connections:

GRANT ALL PRIVILEGES ON {{MYSQL_DATABASE_CM}}.* TO '{{MYSQL_USERNAME_CM}}'@'%';
# as well as 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
# as well as 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
# as well as 
GRANT ALL  ON *.* TO 'root'@'localhost';
MariaDB [(none)]> SHOW GRANTS FOR 'root'@'%';

| Grants for root@%                                                                                                              
| GRANT ALL PRIVILEGES ON *.* TO `root`@`%` IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION 
|1 row in set (0.001 sec)

# or this
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION |
| GRANT ALL PRIVILEGES ON `root`.* TO `root`@`localhost`                                                                                 |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION                                                                          |
+----------------------------------------------------------------------------------------------------------------------------------------+

------------------UPDATE #2------------------------

symfony6-hands-on % docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED      STATUS      PORTS                                            NAMES
bfcac67ebb6c   mariadb:10.8.3           "docker-entrypoint.s…"   5 days ago   Up 2 days   0.0.0.0:3306->3306/tcp                           symfony6-hands-on-mysql-1
2bb1ad5ba56d   adminer                  "entrypoint.sh php -…"   6 days ago   Up 2 days   0.0.0.0:8080->8080/tcp                           symfony6-hands-on-adminer-1
cb9ea779c0bb   schickling/mailcatcher   "sh -c 'mailcatcher …"   6 days ago   Up 2 days   0.0.0.0:1025->1025/tcp, 0.0.0.0:1080->1080/tcp   symfony6-hands-on-mailer-1
Alexey Nikonov
  • 4,958
  • 5
  • 39
  • 66
  • The problem is that your root user is not privileged to access the database from network. You need to update privileges mysql console GRANT ALL PRIVILEGES ON {{MYSQL_DATABASE_CM}}.* TO '{{MYSQL_USERNAME_CM}}'@'%'; You can check privileges by logging in to mysql console to database mysql and run query use mysql;select * from user; – Vladimir Osinskiy Feb 16 '23 at 14:50
  • my question is not duplication because it's about coupling between mariaDB Docker and Symfony with Doctrine – Alexey Nikonov Feb 16 '23 at 15:11
  • @VladimirOsinskiy thanks for assumption, i tried it with your line, as well with my ```MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';``` but it didnt work for me. But i'm able to login to MariaDB console as root with root password – Alexey Nikonov Feb 16 '23 at 15:13
  • You need to grant connections from outside the localhost GRANT ALL PRIVILEGES ON \*.\* TO 'root'@'%'; – Vladimir Osinskiy Feb 16 '23 at 15:14
  • i updated the output after the granting, but as i see the connection is not getting granted. I still receive that error – Alexey Nikonov Feb 16 '23 at 15:25
  • the updated info is in the question – Alexey Nikonov Feb 16 '23 at 15:39
  • please, post logs from `docker ps` command in console – Vladimir Osinskiy Feb 17 '23 at 01:33
  • @VladimirOsinskiy check please, i added it in question – Alexey Nikonov Feb 18 '23 at 20:28
  • I dont know what bug is it, i even tried to create another user (that didnt work), but i installed on another pc with intel processor - and it got installed successfully from the first try from that repository. This bug is appeared on mac m1, i dont know if it appears on other M1s or not... – Alexey Nikonov Feb 19 '23 at 20:27
  • This behavior is due to arm chip-set. Try to add --platform linux/amd64,linux/arm64 to mysql container – Vladimir Osinskiy Feb 20 '23 at 03:29
  • Yep, the line is added ```docker-compose.yml -> services -> mysql -> platform: linux/arm64/v8``` – Alexey Nikonov Feb 20 '23 at 18:55
  • Try to use docker-compose.yml -> services -> mysql -> platform: linux/amd64, not arm – Vladimir Osinskiy Feb 21 '23 at 05:47

0 Answers0