Skip to content
TrySitePrice

Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

Best/Tutorial

This error message usually indicates that the MySQL server is not running or there's a problem with the connection to the MySQL server. Here are a few steps you can try to resolve the issue:

  1. Check if the MySQL service is running:

    systemctl status mysql

  2. Start the MySQL service:

    systemctl start mysql

  3. Ensure that the MySQL service is set to start at boot time:

    systemctl enable mysql

  4. Check if there are any issues with the MySQL configuration file, /etc/my.cnf:
    • Make sure that the socket parameter points to the correct location of the MySQL socket file, /var/lib/mysql/mysql.sock.
    • Check for any errors or misconfigurations in the file.
  5. Check if the MySQL socket file exists and has the correct permissions:

    ls -l /var/lib/mysql/mysql.sock

  6. Try connecting to the MySQL server using the mysql client and specifying the correct socket file location:

    mysql -u <user> -p --socket=/var/lib/mysql/mysql.sock

  7. If all the above steps fail, you may need to check the MySQL error log for more information on the issue:

    tail /var/log/mysql/error.log

rnNote: Replace <user> in step 6 with the actual MySQL user name.