Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Onkovat opened this issue Jun 23, 2016 · 9 comments
Closed

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

Onkovat opened this issue Jun 23, 2016 · 9 comments
Assignees

Comments

@Onkovat
Copy link

Onkovat commented Jun 23, 2016

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: #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.

So how can I solve this then?

Thanks!

@andimov
Copy link
Contributor

andimov commented Jun 23, 2016

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

@Onkovat
Copy link
Author

Onkovat commented Jun 23, 2016

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.

@Onkovat
Copy link
Author

Onkovat commented Jun 23, 2016

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?

@Onkovat
Copy link
Author

Onkovat commented Jun 24, 2016

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. :|

@dswtpvtltd
Copy link

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!

@sagarppanchal
Copy link

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

@vtransy
Copy link

vtransy commented Aug 25, 2019

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/

magento-team pushed a commit that referenced this issue Jan 28, 2020
@rootleet
Copy link

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

@xxxdepy
Copy link

xxxdepy commented Dec 3, 2022

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

Why does this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants