PDOException SQLSTATE(HY000) (2002 can t connect to local MySQL server through socket)

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

Closed

joaco1826 opened this issue

Nov 22, 2017

· 6 comments

Comments

Help!
It only happens when I save a product.

Thanks for your support

The MySQL server is configured to listen on a local Unix socket but it's not listening; I'm not seeing this happen all over the place so I suspect it is most likely something to do with the configuration you're using and it sounds more like a generic Laravel problem than Backpack one.

If it's a mysql configuration issue, it should be in all the files, but it only happens when I want to save, view, delete and edit without problems

It would help, of course, if we knew the minimum of what backpack version you have installed, which Laravel version and so forth...and what database type you think it should be using.

"require": {
"php": ">=5.6.4",
"backpack/base": "^0.7.23",
"backpack/crud": "^3.2",
"doctrine/dbal": "^2.6",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0"
},

Thanks!

Hi @joaco1826 ,

It sounds like a Laravel misconfiguration too me too, not a Backpack-related problem, so I'm going to have to close this.

In case you're using the latest MacOS & MAMP, this is something I've had to do to force Laravel to use the right socket:

DB_CONNECTION=mysql DB_HOST=localhost;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock DB_PORT=3306 DB_DATABASE=backpack_demo2 DB_USERNAME=root DB_PASSWORD=root

Maybe it helps. But again, does not sound like a Backpack bug.

Cheers!

It was not a socket issue. the problem was that the database field updated_at was not by default current_timestamp.

Thanks for the help

I'm getting

'PDO Connection Error: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

error when I'm trying to make too much update and insert. With too much update, I mean 20k-30k transaction per minute. For example, when I try to make a batch processing over 10k records in a table, I'm starting to get this error.

I searched in serverfault and MySQL reference docs, and I found, invalid sock file location or down mysql server can cause this error, but my sock files path is true and mysql server is up. Because normally, I'm able to connect to mysql and run query.

Can connection limit cause this error? My current max_connections variable value is 151, and this can be not enough for 10k transactions per minutes. But as I know, when too much connections opened to mysql, it gives too many connections error not can't connect through socket error.

I have changed, my application to to use mysql_pconnect instead of mysql_connect. I don't know what will happen when I try to run cron job to process 10k records.

Do you have any idea? If I can't found a answer for this problem, I will try to get a big machine for MySQL with 32 gb ram, 4-8 processors and try with this setup.

Symptoms

  • The following error is shown instead of the Plesk login page:

    ERR [panel] SQLSTATE[HY000] [2002] No such file or directory
  • Generation of the login link fails:

    # plesk login
    ERR [panel] SQLSTATE[HY000] [2002] No such file or directory:
    0: /usr/local/psa/admin/externals/Zend/Db/Adapter/Pdo/Abstract.php:144
    ……….
    ERROR: Zend_Db_Adapter_Exception: SQLSTATE[HY000] [2002] No such file or directory (Abstract.php:144)

  • It is possible to login to the Plesk configuration database (psa) using the command:

    # plesk db

  • No errors can be found in the MySQL error log (can be located at /var/log/mysqld.log, /var/log/mariadb/mariadb.log or /var/log/mysql/error.log) even during the restart of the service.

  • Manual running of the backupmng utility fails with the following error:

    # plesk sbin backupmng
    backupmng: Unable to connect to Plesk Database: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (13)
    System error 13: Permission denied
    backupmng: Unable to connect to Plesk Database: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (13)
    System error 13: Permission denied
    backupmng: Unable to connect to the mysql database

  • When deleting a domain or a subscription from Plesk, the following error can be found in the file /var/log/plesk/panel.log:

    PHP Fatal error: Uncaught exception 'PleskMultipleException' with message 'Error during example.com removeZone: dnsmng failed: dnsmng: Unable to connect to Plesk Database: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    System error 2: No such file or directory
    dnsmng: Unable to connect to the mysql database
    System error 2: No such file or directory
    in /opt/psa/admin/plib/Service/Dns/Connector/Plesk.php:14
    Stack trace:
    ..........
    thrown in /opt/psa/admin/plib/Service/Dns/Connector/Plesk.php on line 14

Cause

The sockets specified in the files /etc/psa/psa.conf and /usr/local/psa/admin/conf/php.ini differ from the actual MySQL socket defined in the file /etc/my.cnf (/etc/mysql/my.cnf on Debian and Ubuntu).

Resolution

  1. Connect to the server using SSH.

  2. Make sure that the sockets to connect to the MySQL server specified in the files /etc/psa/psa.conf and /usr/local/psa/admin/conf/php.ini are the same as the socket defined in the file /etc/my.cnf (/etc/mysql/my.cnf on Debian and Ubuntu):

    # grep mysql.sock /etc/my.cnf
    socket=/var/lib/mysql/mysql.sock

    # grep mysql.sock /etc/psa/psa.conf
    MYSQL_SOCKET /var/lib/mysql/mysql.sock

    # grep mysql.sock /usr/local/psa/admin/conf/php.ini
    pdo_mysql.default_socket=”/var/lib/mysql/mysql.sock”

Can't connect to local MySQL server through socket error?

It means either the MySQL server is not installed/running, or the file mysql. sock doesn't exist in /var/lib/mysql/ . There are a couple of solutions for this error. Then try to connect again.

How do I fix MySQL error 2002?

To fix this error, you need to see if MySQL server is already installed and running on your computer. That should start the server and generate the mysql. sock file. You can try to connect to your MySQL server again now.

Can't connect to local MySQL server through socket Ubuntu?

To fix the MySQL socket issue and access denied error for root@localhost , follow the below steps. Stop the MySQL server by executing the command “ sudo service mysql stop “. Create socket location as a placeholder by executing the command “ sudo mkdir -p /var/run/mysqld “.

Can't connect to local MySQL server through socket Centos?

You can fix this problem by adding the same socket line under [client] section inside mysql config. Show activity on this post. Check if your mysqld service is running or not, if not run, start the service. If your problem isn't solved, look for /etc/my.