Software⏱️ 2 min read📅 2026-05-30

How to Fix: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' -- Missing /var/run/mysqld/mysqld.sock

MySQL error: Can't connect to local MySQL server through socket /var/run/mysqld/mysqld.sock (2) - Missing /var/run/mysqld/mysqld.sock

Quick Answer: Start the MySQL server and ensure the socket file exists before attempting to log in as root.

The error message you're encountering, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' -- Missing /var/run/mysqld/mysqld.sock", indicates that the MySQL socket file is missing or not accessible. This issue often arises when MySQL is installed on a system where the socket file is not created automatically.

🛠️ Step-by-Step Verified Fixes

Method 1: Create the Socket File Manually

  1. Step 1: Run the following command in the terminal to create the socket file manually.
# sudo touch /var/run/mysqld/mysqld.sock

Method 2: Start MySQL with the --skip-net-socket Option

  1. Step 1: Run the following command in the terminal to start MySQL with the --skip-net-socket option.
# mysqld_safe --skip-grant-tables --skip-net-socket &

💡 Conclusion

By following these steps, you should be able to resolve the error and regain access to your MySQL server.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions