Marcel Puy
Marcel Puy

Reputation: 33

Symfony 5 - SQLSTATE[HY000] [2002] No such file or directory

I'm running a Symfony 5 project on my Ubuntu machine, and when I try to import my database I had created to my project I get the following error:

enter image description here

The thing is I'm going through a tutorial a second time to create my own project, and the first project works just fine. The DATABASE_URL in the .env files on these two project are the same (double and triple checked),

here's the .env enter image description here

I've tried changing localhost to 127.0.0.1 but the error changes to 'Connection refused', and I also tried adding the real path to the mysql.sock to the php.ini. These are the solutions I've found that apply to my problem, nothing worked so far.

Any ideas would be greatly appreciated!!

Upvotes: 3

Views: 3993

Answers (2)

Alexandre Sherozia
Alexandre Sherozia

Reputation: 1

This problem sometimes occurs, because on Linux (unix) machines, we need to indicate unix_socket="value". You should find "mysql.sock" file in your local server folder and copy/paste the path as its value. e.g. on my distant Gandi server this file is called "mysqld.sock" and lives in /srv/run/mysqld/ . So, the distant .env is : DATABASE_URL="mysql://root:password@localhost/db_name?unix_socket=/srv/run/mysqld/mysqld.sock"
On my local ubuntu this file lives in /opt/lampp/var/mysql/mysql.sock . In my local .env file : DATABASE_URL="mysql://root:password@localhost/db_name?unix_socket=/opt/lampp/var/mysql/mysql.sock"
Hope, it helps someone having the same issue.

Upvotes: 0

Bertyterty
Bertyterty

Reputation: 111

Have you defined a path to your socket in the config/packages/doctrine.yaml? See the marked answer here

I think that setting localhost to 127.0.0.1 fixes your initial problem, but then you are getting connection refused as the server isn't accepting your credentials.

If you aren't using a socket, then you need to pass a password in to your DATABASE_URL:

DATABASE_URL=mysql://root:[email protected]:3306/beers?serverVersion=5.7

Upvotes: 2

Related Questions