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