13

There has been an error processing your request

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

Getting the above error please someone provide me solution to solve this.

  • I've fixed it by changing connection string, make sure that your mysql is on and you have all the tables exists in the database. – Touqeer Shafi Jun 5 '15 at 15:03

10 Answers 10

10

If your server listed in app/etc/local.xml is localhost and this error appears in Magento's error log, but Magento still is running ok, then mysql was restarted and the socket /tmp/mysql.sock or whatever socket file is set up in my.cnf temporarily disappeared.

Because it's missing, the PDO mysql connector reports SQLSTATE[HY000] [2002] No such file or directory

If you are continually getting this error thrown and have no access to Magento aside from the Exception Error page, then mysql has crashed completely and you need your hosting provider to find out why and restart mysql.

9

I had the same issue while installing Magento 2.1.0 with PHP 7.0.13.
I could resolve this issue by setting the database hostname as 127.0.0.1 instead of localhost .

  • Where should this be done? – joeybab3 Aug 26 at 17:09
6

set the database hostname as 127.0.0.1 instead of localhost.

2

This can also happen if ur filesystem is full ... df -h 1st ...ofcourse, mostly u shud get alerts before that...

mysqld wont be running normally, and would be in a "safe" mode

HTH SNS

1

I had this same issue, and I used below to select which php have to use. /usr/local/etc/php/7.2/bin/php bin/magento setup:di:compile

See official docs: SQLSTATE[HY000] [2002] No such file or directory

0

Make sure you edit your app/etc/local.xml properly. If you have no prefixes for your tables make sure the proper line is:

<table_prefix><![CDATA[]]></table_prefix>

NOT

<table_prefix>{{db_prefix}}</table_prefix>
0

This is commonly caused by a different instance of PHP being used by the PHP command line compared to the web server. In particular, mysql.sock might be misconfigured if this is the case.

To determine whether or not you’re using one instance of PHP:

  1. Log in to your Magento server.
  2. Enter the following command:

    php -i | grep 'php.ini'
    

This determines the settings used by the PHP command-line interface (CLI). Note where php.ini is located.

  1. If you haven’t already done so, set up a phpinfo.php on your web server.
  2. Compare the value of Loaded Configuration File from phpinfo.php with the one from php -i.

phpinfo.php shows the php.ini file used by your web server. If it’s different from what's in PHP's php.ini, you must make all PHP settings consistent for both the PHP CLI and the web server.

For additional details, consult the documentation provided with your web server.

0

I have several versions of PHP available to me via the shell - typing php and pressing tab shows which ones my autocomplete knows about.

For me, PHP 5.4, 5.5 and 5.6 were all working fine, but PHP 7 wasn't finding the mysql.sock, and was crashing with the "SQLSTATE[HY000] [2002] No such file or directory error" discussed in this question.

# Prints [ok]
echo "<?php print(new mysqli('localhost', 'root', 'root', 'mysql') ? '[ok]' : '[error]').PHP_EOL; ?>" | php-5.6.20

# Prints [error] and shows a warning
echo "<?php print(new mysqli('localhost', 'root', 'root', 'mysql') ? '[ok]' : '[error]').PHP_EOL; ?>" | php-7.0.8

To see where your mysql server has its socket, use this command:

cat /etc/mysql/my.cnf | grep socket

In my case, with Percona Mysql installed in my vagrant system the sock socket file happened to live here:

/var/run/mysqld/mysqld.sock

(notice that it is called mysqld not simply mysql)

I have several versions of php to choose from and these commands showed me which ones had issues and which ones were fine:

The answer for me was simply to include code in the vagrant provisioner script to create a symlink between /tmp/mysql.sock and /var/run/mysqld/mysqld.sock

if [ ! -L /tmp/mysql.sock ]; then
    echo "Creating symbolic link for php 7 to connect to mysql.sock"
    ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
fi

With the new symlink in place, the test script given before now works perfectly for all versions of PHP and I can use localhost in my code instead of having to give the 127.0.0.1 IP address.

0

I get the same error "SQLSTATE[HY000] [2002] No such file or directory". And found that MySQL service was stopped. I started my MySQL service and its working fine.

0

This seems to be wrong PHP version issue, you need to select which php have to use to run the command as follows:

/Applications/MAMP/bin/php/php7.1.20/bin/php bin/magento setup:upgrade

PS: Above sample is for MAC, you can do it similar way for windows or unix as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.