Magento Error: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Magento Error: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

September 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Error: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Solving MySQL Connection Errors in Magento

Introduction

As you’re migrating your Magento application from Blue Host to GoDaddy, you’ve encountered a common SQL connection error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'. Don’t worry—we’ll walk through this step-by-step and get your e-commerce store up and running again.

Understanding the Error

The error message indicates that Magento is unable to establish a connection with your MySQL database. This could be due to several reasons:

  1. The MySQL service might not be running on your new server.
  2. The MySQL configuration file (my.cnf) may have incorrect socket path settings.
  3. Your user credentials (username/password) for the Magento database are incorrect.

Troubleshooting the Issue

Step 1: Check if MySQL is Running

First, let’s ensure that the MySQL server is actually running on your GoDaddy account.

  • Open a terminal or SSH into your GoDaddy server.
  • Run this command to check the status of the MySQL service:
sudo systemctl status mysql

If it shows “active (running)”, proceed to the next step. If not, start the service using sudo systemctl start mysql.

Step 2: Verify Database Credentials

Ensure your Magento database credentials are correct:

  • Log into cPanel on GoDaddy.
  • Navigate to the “Databases” section and locate your Magento database.
  • Check if the username and password match what’s configured in your app/etc/local.xml file.

Step 3: Modify MySQL Configuration

If everything looks good, let’s modify the MySQL configuration to point to the correct socket path:

  1. Open the my.cnf file located in /etc/mysql/.
  2. Locate the [mysqld] section.
  3. Add or update this line for the socket path:
socket = /var/run/mysqld/mysqld.sock
  1. Save and close the file.

Step 4: Update Magento Configuration

Finally, let’s double-check the database connection settings in your local.xml file:

  1. Open app/etc/local.xml.
  2. Locate the <resources> section.
  3. Ensure the host, username, password, and db_name for both <default_setup> and <default_read> match your GoDaddy MySQL database settings.

Conclusion

By following these steps, you should now be able to resolve the SQL connection error in Magento. If you’re still experiencing issues, double-check that:

  • The MySQL service is definitely running.
  • Your database credentials are correct.
  • The socket path in my.cnf matches the actual location of your MySQL socket.

Remember, if you need further assistance or want to learn more about Magento development and troubleshooting, feel free to explore our comprehensive guides at Laravel Company.

Happy coding! Let me know in the comments if this solution helped resolve your issue.

Database Configuration Customers Errors

Our network