Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

varundavda's avatar

Mysql connection error

I am getting this mysql connection error, when I type mysql from the terminal.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I don't know what can be done to solve this. Can you all please guide me?

Thanks.

0 likes
1 reply
zachleigh's avatar

This could be due to several reasons. Most common is that the sock file doesnt exist. Verify that the file '/tmp/mysql.sock' exists and if it doesn't, see if one exists elsewhere on your system. If you have one somewhere else, set the correct file path in my.cnf. Then restart mysql and see if it worked.

1 like

Please or to participate in this conversation.