An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES)
Asked Answered
L

5

7

I followed this documentation to add doctrine to my symfony project(v4.2). But when doctrine is installed it deosn't add this line to my project ( in my .env file like mentioned in the doc ):

DATABASE_URL="mysql://db_user:[email protected]:3306/db_name"

So I added it manually like this :

DATABASE_URL="mysql://[email protected]:3306/db_school"

and used this commande to create the database :

php bin/console doctrine:database:create

and it gives me this error :

In AbstractMySQLDriver.php line 93: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES)

In PDOConnection.php line 31: SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES)
In PDOConnection.php line 27: SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES)

Even I changed the user and password it still dosn't recognize it . Any idea why it dosn't work ? I will appreciate it .

Lona answered 15/4, 2019 at 10:59 Comment(6)
Do you have .env.local file which may override this variable?Sputter
No Sir . I don't have it .Lona
The error message is inconsistent with the config line you add ! I think that's a bad thing to use root. Create an user and grant him with "administration rights". Do you have a database named "db_school" in your DBMS ? Do you have an user named "db_user" in your DBMS ?Stigma
No Sir ! I dont have them. I just have the root as user name .and database dosnt existLona
your root username have a password ? if yes then try : DATABASE_URL="mysql://root:[email protected]:3306/db_school" and php bin/console doctrine:database:createTierratiersten
No sir it doesnt have a passwordLona
L
1

This method seem to not work for me I dont kniw why but it worked this way :

  • So I used Flex to install doctrine :

composer require doctrine

Then I run this :

composer require orm

  • then I went to my file .env and I found my database syntax generated automaticlyy and everything worked fine .

  • Also I deleted the other sql processors that were open on my computer ( i hv installed sql server too + wamp which explaine the conflict that I have) and then re-opened my wamp server and everything is working fine.

Lona answered 16/5, 2019 at 16:19 Comment(2)
you did not solve it, you don't even understand why the error exist. instead you installed a bunch of "$(/%)"($/ and that fixed it for you. The answeres above are 100% correct you just forgot the " : " symbol for empty password. Did you just want to answere your own question?Cooee
That's a bold statementMarshmallow
S
6

I think you have to create an user "db_user" with password in your DBMS. Then grant him with "Administration" rights. Then correct .env's database configuration line :

DATABASE_URL="mysql://db_user:[email protected]:3306/db_name"
Stigma answered 15/4, 2019 at 11:23 Comment(3)
I just tried your suggestion but I still have the same probleme :Lona
Search the string "db_user" in all project's files and check if it exists only where it has to existsStigma
I searched but it doesn't exist . I don't know where the problem come fromLona
S
3

Try using the same syntax like you have a password, just enter nothing where password suppose to be:

DATABASE_URL="mysql://root:@127.0.0.1:3306/db_school"

As it's explained here: https://github.com/doctrine/DoctrineBundle/issues/746#issuecomment-351788298

Selfregulated answered 16/4, 2019 at 7:9 Comment(0)
L
1

This method seem to not work for me I dont kniw why but it worked this way :

  • So I used Flex to install doctrine :

composer require doctrine

Then I run this :

composer require orm

  • then I went to my file .env and I found my database syntax generated automaticlyy and everything worked fine .

  • Also I deleted the other sql processors that were open on my computer ( i hv installed sql server too + wamp which explaine the conflict that I have) and then re-opened my wamp server and everything is working fine.

Lona answered 16/5, 2019 at 16:19 Comment(2)
you did not solve it, you don't even understand why the error exist. instead you installed a bunch of "$(/%)"($/ and that fixed it for you. The answeres above are 100% correct you just forgot the " : " symbol for empty password. Did you just want to answere your own question?Cooee
That's a bold statementMarshmallow
F
0

For me all the configurations were right. I found that this error was happening because of the service "MySQL 80" wasn't running, to fix that:

  1. Press the "Windows" button and search for "services" Image
  2. Stop the service "MySQL" Image
  3. Start the service "MySQL 80" Image

Now try again and the problem should be solved

Fibrosis answered 2/7, 2023 at 18:38 Comment(0)
R
0

Also pay attention that the password shouldnt contain special characters, or it should be encoded. See:

"If the username, password, host or database name contain any character considered special in a URI (such as +, @, $, #, /, :, *, !, %), you must encode them. See RFC 3986 for the full list of reserved characters or use the urlencode function to encode them. In this case you need to remove the resolve: prefix in config/packages/doctrine.yaml to avoid errors: url: '%env(DATABASE_URL)%'"

Rebate answered 27/2, 2024 at 19:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.