Pdoexception Sqlstate[Hy000] [2002] No Such File or Directory

PDOException SQLSTATE[HY000] [2002] No such file or directory

The error message indicates that a MySQL connection via socket is tried (which is not supported).

In the context of Laravel (artisan), you probably want to use a different / the correct environment. Eg: php artisan migrate --env=production (or whatever environment). See here.

error in laravel : SQLSTATE[HY000] [2002] No such file or directory, the path of the socket file don't work

Are you looking for connect to a local database or a remote database (a database located on other computer/server) ?

On Unix, MySQL programs treat the host name localhost specially,
in a way that is likely different from what you expect compared to other network-based programs.

For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number.

To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by using the --protocol=TCP option.

protocol could be {TCP|SOCKET|PIPE|MEMORY}

in short: you don't have to specify a sock file for remote connections.

SQLSTATE[HY000] [2002] No such file or directory

After searching, I found this post:

Setting up Laravel on a Mac php artisan migrate error: No such file or directory

Once I added

'unix_socket' => '/tmp/mysql.sock’,

to my database.php in the mysql array, it worked. Not sure exactly why that works, but it does.

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

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:password@127.0.0.1:3306/beers?serverVersion=5.7

Illuminate\Database\QueryException SQLSTATE[HY000] [2002] No such file or directory but migrations works

I found the answer to my issue. I used MAMP and Docker at the same time. The problem is that Mama is on the server, and docker is lokal on the computer. So I got two databases. But the password for the database was not set in Docker. So I got access to my server database with the properties in env. And no access to my docker database, which the eloquent wanted to store. So I deleted MAMP from my computer and tried to access MySQL with

docker exec -it MySQL MySQL -uroot -p

but the password was wrong. So I used the command of What's the default password in docker container MySQL-server when you don't set one? from nischay, and this generates a new password. I set this password in docker exec -it MySQL MySQL -uroot -p, and I was in the MySQL bash. After this, I reset the password with ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password;

SQLSTATE[HY000] [2002] No such file or directory when i try to php artisan migrate

I can see from the screenshot that your phpMyAdmin is connecting to the database at 8889 port, your env has DB_PORT=3306, change to DB_PORT=8889.

Summary of the comment section:

Dan is using MAMP, so the config for mysql connection should contain (for default MAMP settings):

DB_HOST=localhost
DB_PORT=8889
DB_USERNAME=root
DB_PASSWORD=root

Illuminate\Database\QueryException SQLSTATE[HY000] [2002] No such file or directory

As per your error screenshot I have seen in your question. Now its connection error. Check you have put correct username,password, dbname and server name.
If you are using mariadb, please try specifying port in servername like localhost:3306 or 127.0.0.1:3306

For Troubleshooting, visit http://localhost/phpmyadmin and check whether your given credentials help you in logging.



Related Topics



Leave a reply



Submit