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

Created on 23 Jun 2016  路  8Comments  路  Source: magento/magento2

I'm using Magento 2.0.7 and I ran into this error that I can't find to resolve.

It happenes when on terminal via SSH I try to run a simple cache flush command. The error message is:

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

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

cache:flush [--bootstrap="..."] [types1] ... [typesN]`

When I let magento show that I run in dev mode then nothing happens.

Now I have read this article http://devdocs.magento.com/guides/v2.0/install-gde/trouble/php/tshoot_phpini.html

And really, the Loaded Configuration File had a different path. Now this was changed. It is still a bit different like /opt/phpfcgi-5.6/lib instead 5.6.22 but the previous dir is a redirect to the first one so they are the same files. I guess that would not mean problems, right?

I found now that here it is suggested that it might be a cookie problem: https://github.com/magento/magento2/issues/737#issuecomment-62965401

It's true that I run my magento on a subdomain though I can't change that in order to test if it would be a solution. And it would be no real solution anyway from a magento dev point of view.

So how can I solve this then?

Thanks!

Most helpful comment

I had this same issue due to multiple versions of PHP on my mac,
simple I used below below to select which php have to use
/Applications/MAMP/bin/php/php7.1.20/bin/php bin/magento setup:upgrade

All 8 comments

@Onkovat, thank you for reporting! Could you please provide description according to the template to allow us research this issue?

andimov, I'm really not sure what to write into the template:

Steps to reproduce

  1. Install Magento from develop branch.
  2. [Example] Add Configurable Product to the cart.
  3. ...

Expected result

  1. [Example] Configurable product added to the shopping cart.
  2. ...

Actual result

  1. [Example] Error message appears: "Cannot save quote".
  2. [Screenshot, logs]
  3. ...

I can't install from development branch since I do not know how to do it. I installed the newest 2.0.7 version of magento though. The shop is on a subdomain of a topleveldomain. I can log in via SSH and can run commands like magento deploy:mode:show successfully and I could change it to developer mode. Though it does not work to run a command like magento cache:flush in terminal. Because always the error message

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

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

cache:flush [--bootstrap="..."] [types1] ... [typesN]`

appears.

What I found and did in trying to solve it is this: Now I have read this article http://devdocs.magento.com/guides/v2.0/install-gde/trouble/php/tshoot_phpini.html

And really, the Loaded Configuration File had a different path. Now this was changed. It is still a bit different like /opt/phpfcgi-5.6/lib instead 5.6.22 but the previous dir is a redirect to the first one so they are the same files. I guess that would not mean problems, right?

I found now that here it is suggested that it might be a cookie problem: #737 (comment)

It's true that I run my magento on a subdomain though I can't change that in order to test if it would be a solution. And it would be no real solution anyway from a magento dev point of view.

I think it might be that the subdomain can be a problem though I think that should not happen because it should be quite normal to run a magento shop on a subdomain.

Otherwise I do not have a clue about what could be wrong.

I'm not sure if you can follow the trails this way but what I did was only installing the magento on that subdomain.

Andrii Kasian
kandy
https://github.com/kandy
I'm not sure how to reference you but I will try since github seems to not have a personal message system.

I noticed in the other thread that you suggested as the solution to move the shop to a maindomain and that it might have to do with cookies and such. I don't have a clue how this could be related but I can not move my shop to a main domain. So can you help to solve the issue in another way maybe?

Probably no bug... It seems I had no access to the database through terminal. I'm not really experienced with unix so I thought the error has to lie in magento. :|

After a lot of struggle I finally fixed the issue of SQLSTATE[HY000] [2002] No such file or directory on MAC MAMP server.

I create /etc/my.cnf file and make an entry of following line of code 馃憤

[mysqld]
socket=/Applications/MAMP/tmp/mysql/mysql.sock

[client]
socket=/Applications/MAMP/tmp/mysql/mysql.sock

This I created the /.bash_profile and make an entry of

export PATH=/Applications/MAMP/bin/php/php7.0.15/bin:/Applications/MAMP/Library/bin:$PATH

Then It start work!

I had this same issue due to multiple versions of PHP on my mac,
simple I used below below to select which php have to use
/Applications/MAMP/bin/php/php7.1.20/bin/php bin/magento setup:upgrade

yeah the solution of @sagarppanchal and @dswtpvtltd will help to resolve this issue.

I found a better way to resolve this issue is:

get error:聽SQLSTATE[HY000] [2002] No such file or directory

solution: create symlink from mamp mysql.sock to /tmp/mysql.sock

ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

The cause of my case is Mamp install mysql and socket in other directory and Magento 2 looking mysql.sock in default place. So we just need to link the default place to Mamp place. This will resolve this issue.

I noted some other issues I got when install mamp here:
https://mrvts.wordpress.com/2019/08/25/mac-pro-install-and-use-mamp-pro-for-magento/

Goto

  1. app/etc/
  2. open env.php in a text editor
  3. change 'host' => 'localhost' to 'host' => '127.0.0.1',

That worked for me

Was this page helpful?
0 / 5 - 0 ratings