Moving MySQL/MariaDB data files – SQLSTATE[HY000] [2002] No such file or directory – DO NOT ALTER localhost ->

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

Tricky one this…

I moved MySQL (MariaDB actually) data files – very carefully.  Basically,

Stopped services httpd and mariadb.
Edited MySQL conf files for datadir and socket.
Copied data files – set ownnership etc.
Restarted services httpd and mariadb.

All fine except not fine.

Run web app and get:
SQLSTATE[HY000] [2002] No such file or directory

Answers seem to be change the DB settings – change ‘localhost’ to ‘’  —  NOT REALLY CORRECT!!!

Turns out – PHP also has settings for where the MySQL socket file is:
pdo_mysql.default_socket =

and a couple others.

These need to be set to the new value of where the socket file is.  Then all works as before.

I think – fairly sure – that changing ‘localhost’ to ‘’ makes all database connections then act over IP – not through a socket – which is probably slower.

Change the values in php.ini and restart the web server and all should be well.


Share Post :

Leave a Reply