SQLSTATE[HY000] [2002] No such file or directory error The Next CEO of Stack OverflowError...

% symbol leads to superlong (forever?) compilations

Science fiction (dystopian) short story set after WWIII

Opposite of a diet

Visit to the USA with ESTA approved before trip to Iran

Increase performance creating Mandelbrot set in python

Anatomically Correct Mesopelagic Aves

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

How to write the block matrix in LaTex?

What is the point of a new vote on May's deal when the indicative votes suggest she will not win?

Putting a 2D region plot under a 3D plot

What is meant by a M next to a roman numeral?

How to use tikz in fbox?

Too much space between section and text in a twocolumn document

Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?

What does this shorthand mean?

How do spells that require an ability check vs. the caster's spell save DC work?

How to write papers efficiently when English isn't my first language?

Why do professional authors make "consistency" mistakes? And how to avoid them?

Is HostGator storing my password in plaintext?

Can the Reverse Gravity spell affect the Meteor Swarm spell?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Why do remote companies require working in the US?

Implement the Thanos sorting algorithm

Is it my responsibility to learn a new technology in my own time my employer wants to implement?



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



The Next CEO of Stack OverflowError Processing Request: SQLSTATE[HY000] [2002] No such file or directory"Socket Server and Mage.php base class - MySQL server has gone awayPDO Exception error on indexIf there is one item left in inventory I get SQLSTATE ERRORSQLSTATE[42S22]: Column not found: 1054 Unknown column 'session_id' in 'field list'F5 key Flood and “Error log record number reporting” pageError logging into magento admin, magento-1.9Magento is ignoring host in local.xml and attempting to connect via Unix SocketMigration Error - Exception: SQLSTATE[HY000] [2002]Error Processing Request: SQLSTATE[HY000] [2002] No such file or directory"Shop crashes SQLSTATE[HY000] in error reports












10















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.










share|improve this question

























  • 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















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.










share|improve this question

























  • 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












10








10


2






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.










share|improve this question
















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.







mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 13 '15 at 7:55









dh47

1,68811431




1,68811431










asked Jan 13 '15 at 6:05









codercoder

37321126




37321126













  • 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



















  • 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

















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





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










9 Answers
9






active

oldest

votes


















9














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.






share|improve this answer

































    5














    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 .






    share|improve this answer































      4














      set the database hostname as 127.0.0.1 instead of localhost.






      share|improve this answer































        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






        share|improve this answer































          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>





          share|improve this answer

































            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.






            share|improve this answer


























            • This can happen - I think I am facing this right now. But why? Any specific ideas on what to check in these ini files?

              – VladFr
              Jan 23 '17 at 13:57






            • 4





              Rather You may provide some courtesy to this page devdocs.magento.com/guides/v2.0/install-gde/trouble/php/…

              – Shan
              Feb 27 '17 at 12:03



















            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.






            share|improve this answer































              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.






              share|improve this answer































                0














                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





                share








                New contributor




                Lee Derting is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





















                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "479"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f51948%2fsqlstatehy000-2002-no-such-file-or-directory-error%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  9 Answers
                  9






                  active

                  oldest

                  votes








                  9 Answers
                  9






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  9














                  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.






                  share|improve this answer






























                    9














                    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.






                    share|improve this answer




























                      9












                      9








                      9







                      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.






                      share|improve this answer















                      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.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jan 13 '15 at 7:55

























                      answered Jan 13 '15 at 7:49









                      Fiasco LabsFiasco Labs

                      6,67841944




                      6,67841944

























                          5














                          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 .






                          share|improve this answer




























                            5














                            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 .






                            share|improve this answer


























                              5












                              5








                              5







                              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 .






                              share|improve this answer













                              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 .







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Dec 2 '16 at 12:58









                              JinoJino

                              37124




                              37124























                                  4














                                  set the database hostname as 127.0.0.1 instead of localhost.






                                  share|improve this answer




























                                    4














                                    set the database hostname as 127.0.0.1 instead of localhost.






                                    share|improve this answer


























                                      4












                                      4








                                      4







                                      set the database hostname as 127.0.0.1 instead of localhost.






                                      share|improve this answer













                                      set the database hostname as 127.0.0.1 instead of localhost.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Dec 20 '16 at 17:59









                                      guestguest

                                      411




                                      411























                                          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






                                          share|improve this answer




























                                            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






                                            share|improve this answer


























                                              2












                                              2








                                              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






                                              share|improve this answer













                                              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







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Mar 8 '17 at 11:05









                                              shaheen shahshaheen shah

                                              211




                                              211























                                                  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>





                                                  share|improve this answer






























                                                    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>





                                                    share|improve this answer




























                                                      0












                                                      0








                                                      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>





                                                      share|improve this answer















                                                      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>






                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Aug 3 '15 at 19:41









                                                      brentwpeterson

                                                      4,32653475




                                                      4,32653475










                                                      answered Aug 3 '15 at 19:18









                                                      AlexLAlexL

                                                      166110




                                                      166110























                                                          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.






                                                          share|improve this answer


























                                                          • This can happen - I think I am facing this right now. But why? Any specific ideas on what to check in these ini files?

                                                            – VladFr
                                                            Jan 23 '17 at 13:57






                                                          • 4





                                                            Rather You may provide some courtesy to this page devdocs.magento.com/guides/v2.0/install-gde/trouble/php/…

                                                            – Shan
                                                            Feb 27 '17 at 12:03
















                                                          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.






                                                          share|improve this answer


























                                                          • This can happen - I think I am facing this right now. But why? Any specific ideas on what to check in these ini files?

                                                            – VladFr
                                                            Jan 23 '17 at 13:57






                                                          • 4





                                                            Rather You may provide some courtesy to this page devdocs.magento.com/guides/v2.0/install-gde/trouble/php/…

                                                            – Shan
                                                            Feb 27 '17 at 12:03














                                                          0












                                                          0








                                                          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.






                                                          share|improve this answer















                                                          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.







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Dec 2 '16 at 13:31









                                                          7ochem

                                                          5,81493768




                                                          5,81493768










                                                          answered Dec 2 '16 at 13:12









                                                          gelanivishalgelanivishal

                                                          805620




                                                          805620













                                                          • This can happen - I think I am facing this right now. But why? Any specific ideas on what to check in these ini files?

                                                            – VladFr
                                                            Jan 23 '17 at 13:57






                                                          • 4





                                                            Rather You may provide some courtesy to this page devdocs.magento.com/guides/v2.0/install-gde/trouble/php/…

                                                            – Shan
                                                            Feb 27 '17 at 12:03



















                                                          • This can happen - I think I am facing this right now. But why? Any specific ideas on what to check in these ini files?

                                                            – VladFr
                                                            Jan 23 '17 at 13:57






                                                          • 4





                                                            Rather You may provide some courtesy to this page devdocs.magento.com/guides/v2.0/install-gde/trouble/php/…

                                                            – Shan
                                                            Feb 27 '17 at 12:03

















                                                          This can happen - I think I am facing this right now. But why? Any specific ideas on what to check in these ini files?

                                                          – VladFr
                                                          Jan 23 '17 at 13:57





                                                          This can happen - I think I am facing this right now. But why? Any specific ideas on what to check in these ini files?

                                                          – VladFr
                                                          Jan 23 '17 at 13:57




                                                          4




                                                          4





                                                          Rather You may provide some courtesy to this page devdocs.magento.com/guides/v2.0/install-gde/trouble/php/…

                                                          – Shan
                                                          Feb 27 '17 at 12:03





                                                          Rather You may provide some courtesy to this page devdocs.magento.com/guides/v2.0/install-gde/trouble/php/…

                                                          – Shan
                                                          Feb 27 '17 at 12:03











                                                          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.






                                                          share|improve this answer




























                                                            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.






                                                            share|improve this answer


























                                                              0












                                                              0








                                                              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.






                                                              share|improve this answer













                                                              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.







                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Jan 11 '18 at 16:37









                                                              Martin FrancisMartin Francis

                                                              113




                                                              113























                                                                  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.






                                                                  share|improve this answer




























                                                                    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.






                                                                    share|improve this answer


























                                                                      0












                                                                      0








                                                                      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.






                                                                      share|improve this answer













                                                                      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.







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Jul 11 '18 at 8:52









                                                                      PMBPMB

                                                                      392220




                                                                      392220























                                                                          0














                                                                          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





                                                                          share








                                                                          New contributor




                                                                          Lee Derting is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                          Check out our Code of Conduct.

























                                                                            0














                                                                            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





                                                                            share








                                                                            New contributor




                                                                            Lee Derting is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                            Check out our Code of Conduct.























                                                                              0












                                                                              0








                                                                              0







                                                                              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





                                                                              share








                                                                              New contributor




                                                                              Lee Derting is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.










                                                                              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






                                                                              share








                                                                              New contributor




                                                                              Lee Derting is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.








                                                                              share


                                                                              share






                                                                              New contributor




                                                                              Lee Derting is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.









                                                                              answered 8 mins ago









                                                                              Lee DertingLee Derting

                                                                              1




                                                                              1




                                                                              New contributor




                                                                              Lee Derting is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.





                                                                              New contributor





                                                                              Lee Derting is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.






                                                                              Lee Derting is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.






























                                                                                  draft saved

                                                                                  draft discarded




















































                                                                                  Thanks for contributing an answer to Magento Stack Exchange!


                                                                                  • Please be sure to answer the question. Provide details and share your research!

                                                                                  But avoid



                                                                                  • Asking for help, clarification, or responding to other answers.

                                                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                                                  To learn more, see our tips on writing great answers.




                                                                                  draft saved


                                                                                  draft discarded














                                                                                  StackExchange.ready(
                                                                                  function () {
                                                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f51948%2fsqlstatehy000-2002-no-such-file-or-directory-error%23new-answer', 'question_page');
                                                                                  }
                                                                                  );

                                                                                  Post as a guest















                                                                                  Required, but never shown





















































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown

































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown







                                                                                  Popular posts from this blog

                                                                                  “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                                                                                  How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                                                                                  夢乃愛華...