Warning: Pdo::_Construct(): [2002] No Such File or Directory (Trying to Connect via Unix:///Tmp/Mysql.Sock) In

Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in

You are using a Unix socket. When reading "localhost" MySQL client libraries don't interpret it as TCP host "localhost" and resolve that name but use the default Socket location. For using TCP on the local machine you have to use 127.0.0.1 as hostname.

To specify the past use unix_socketinstead of host in the DSN. The location of the socket used for localhost can be defined at compile time or in some versions of PHP using pdo_mysql.default_socket in the php.ini.

MySQL connection not working: 2002 No such file or directory

If you use Linux: the path to the mysql.sock file is wrong. This is usually because you are using (LAMPP) XAMPP and it isn't in /tmp/mysql.sock

Open the php.ini file and find this line:

mysql.default_socket

And make it

mysql.default_socket = /path/to/mysql.sock

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.

Linked my file to nothing and overwrote mysql.sock

Just found a forum that says the following should work on fedora

touch /var/lib/mysql/mysql.sock
cd /tmp
ln -s /var/lib/mysql/mysql.sock .

Please note the . in the end.

service mysql restart

Thats it.

Warning: mysqli_connect(): (HY000/2002): No such file or directory

Alright, I just found the solution. The problem turned out to be that the host shouldn't have been localhost, but 127.0.0.1. I always thought localhost and 127.0.0.1 was the same, but it turned out to be different.

So maybe as a tip for future users, always use the ip when in doubt.



Related Topics



Leave a reply



Submit