How to overcome the "Error SQLSTATE[HY000] [2002] No such file or directory" message

Describe the procedure to prevent the "Error SQLSTATE[HY000] [2002] No such file or directory" error message. It applies here to a Synology NAS, but must be able to work elsewhere.

May 31, 2020 - 22:41
May 31, 2020 - 23:03
 0  419
How to overcome the "Error SQLSTATE[HY000] [2002] No such file or directory" message

I came across this blocking error when I wanted to install Humhub on my Synology NAS.
But I suppose that the solution which I propose must be able to be used with many applications where the same error message appears.

In my case, the problem was due to a difference between the name of the socket file used by PHP and that used by MySQL.

Here is what I did to resolve this problem.
But of course I cannot guarantee that this is the solution for everyone.


The operations below assume that you have installed and configured:

  • DSM Web Station
  • MySQL (MariaDB 10 for me)
  • PHP (7.3 for me)
  • ... and that you have allowed an SSH access.

Even if you are not on a Synology NAS, read on, the explanation for the error may be the same for you.


  • Connect to your NAS with your SSH tool unsing your admin login
  • Using a command like the following search for the MySQL configuration file my.cnf
sudo find / -name "my.cnf" ! -path "/proc/*" ! -path "/volume1/*" ! -path "/sys/*" ! -path "/run/*"​

Usually the password is the same as the one used for your SSH connection.
Note that the ! -path options are not necessary, they just speed up the search by avoiding browsing trees where it is certain that the file will not be present.
Chez moi, le fichier est le suivant /usr/local/mariadb10/etc/mysql/my.cnf.

  • Select and copy the complete path of the found file. 
  • Now, look for the current MySQL socket file name using a command like this one
more /usr/local/mariadb10/etc/mysql/my.cnf | grep socket​

The my.cnf file path I have used in the above command is mine. Of course, you should use yours if it is different.
On my NAS, this command displays
socket = /run/mysqld/mysqld10.sock

  • Again, select and copy the complete path of the found socket.
  • Now, turn to your NAS Web Station tool.
  • Choose Web Station > PHP Parameters, then select your current PHP version.
  • Click on the « Update » button puis the last tab.
  • Look for the mysqli.default.socket parameter.
  • Replace the socket file name pasting the one in the clipboard.
  • Do the same with the pdo_mysql.default_socket parameter if you use the PDO library.
  • Note that if you are not working on a Synology NAS, you should raplce the values inside your php.ini file.

Small important addition, if ever the Yii framework is used

  • In the file protected/config/dynamic.php, don't forget to add « ;unix_socket=/run/mysqld/mysqld10.sock » at the end of the dsn (using your own socket path)
    If not the cron jobs won't work (I also struggled to understand this point)

The problem that brought you here should no longer happen.
But nothing says that you will not have others after this one. ;-)

Georges Je suis un ingénieur informaticien officiellement à la retraite (mais pas complètement). Mon métier a toujours été une passion. C'est pourquoi je ne me contente pas de me retirer chez moi, à faire pousser des tomates et promener mon chien. Et, soyez sûr que ce n'est pas uniquement parce que je n'ai ni potager, ni chien. Quant à mon chat, heureusement, il est capable de se promener tout seul ! J'ai en fait décidé de garder un pied, voire deux, dans l'informatique. Par conséquent, si jamais vous avez besoin de services de conseil, accompagnement, suivi de projet, formation ou développement, contactez-moi ! Nous discuterons alors de vos besoins ainsi que de mon tarif, puis, peut-être tomberons-nous d'accord afin de collaborer ?