Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Problem with php bin/console doctrine:database:create#47057

Answeredbycaigner
caigner asked this question inQ&A
Discussion options

Hi!

I am developing on a Linux box.

I am completely new to Symfony and am on my second day, following the tutorials on SymfonyCast.

I am stuck at the following point:

I have Apache and MySQL installed, so I am not using Docker.
In .env I have edited the setting for DATABASE_URL.

When I try to run either

php bin/console doctrine:database:create

or

symfony console doctrine:database:create

I get

In ExceptionConverter.php line 103:                                                                                                                                                       An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: Yes)                                                                                                                                                      In Exception.php line 30:                                                                                                                  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: Yes)                                                                                                                  In Driver.php line 28:                                                                                                                  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: Yes)

I even tried

export DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4"

on the command line, but

symfony var:export --multiline

does not show DATABASE_URL.

Any suggestions, how I should proceed? And no, installing and using Docker is not an option.

Thanks,
Christian

You must be logged in to vote

After some more tinkering and researching I found the solution:

Instead of

DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4"

I had to write

DATABASE_URL="mysql://db_user:db_password@localhost:3306/db_name?serverVersion=5.7&charset=utf8mb4"

Now it works. But why this was necessary, I don't understand, because both root@127.0.0.1 and root@localhost are in my mysql user table.

Replies: 2 comments 3 replies

Comment options

After some more tinkering and researching I found the solution:

Instead of

DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4"

I had to write

DATABASE_URL="mysql://db_user:db_password@localhost:3306/db_name?serverVersion=5.7&charset=utf8mb4"

Now it works. But why this was necessary, I don't understand, because both root@127.0.0.1 and root@localhost are in my mysql user table.

You must be logged in to vote
3 replies
@fd6130
Comment options

I'm facing the same issue here. Replace 127.0.0.1 to localhost works again.. not sure why though.

@alexislefebvre
Comment options

Is it trying to connect through socket when you uselocalhost?

It was the case 10 years ago, I don't know if that's still true:

In Linux and other *nixes, MySQL will assume you want to use a socket if you connect to the host "localhost" (which would be the default hostname).

Source on Super User

@ihebgrayaa
Comment options

You just need to insert the correct vesrsion ?serverVersion=5.7

Answer selected bycaigner
Comment options

HI,

With symfony 6.4 and php 8.2.14 I solved this problem.

When starting a symfony project and creating the .env

Before : DATABASE_URL="mysql://root:root@127.0.0.1:3306/app:!ChangeMe!?serverVersion=5.7.24"
After : DATABASE_URL="mysqli://root:root@127.0.0.1:3306/app:!ChangeMe!?serverVersion=5.7.24"

and it works with MAMP

That's it, if it can be useful to others and not go around in circles for several days!

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
5 participants
@caigner@alexislefebvre@fd6130@ihebgrayaa@Auderick

[8]ページ先頭

©2009-2025 Movatter.jp