MySQL error 2002: Can't connect through socket
The client tried the local Unix socket and found no server there. The server isn't running, uses another socket path, or you meant a TCP connection.
- Error number
2002- Name
CR_CONNECTION_ERROR- Category
- Connection and client
What it means
When you connect to localhost on Unix, MySQL clients use a Unix socket file instead of TCP. 2002 means the socket file doesn't exist or nothing is listening on it. The number in brackets is the operating-system error, such as (2) for no such file and (111) for connection refused.
This is a client error: the request never reached a server.
Common causes
- The MySQL server isn't running, or it crashed at startup.
- The server's socket is in a different place than the client expects (for example
/var/run/mysqld/mysqld.sockversus/tmp/mysql.sock). - The server runs in Docker or on another machine, so there is no local socket; you need TCP.
- Permissions on the socket directory stop the client from reaching it.
How to fix it
-
Check that the server is running and read its error log if it isn't, for example with
systemctl status mysqlon Linux orbrew services liston macOS. -
Connect over TCP instead of the socket by using
127.0.0.1rather thanlocalhost, or--protocol=TCP.mysql -h 127.0.0.1 -P 3306 -u app -p
-
If the server runs locally, find its socket path and point the client at it.
-- On the server: SHOW VARIABLES LIKE 'socket'; -- Client: mysql --socket=/var/run/mysqld/mysqld.sock -u app -p
Related errors
2003Can't connect to MySQL server on host2005Unknown MySQL server host2013Lost connection to MySQL server during query53SQL Server: Network-related or instance-specific08006PostgreSQL: connection failure
More connection and client errors
2006MySQL server has gone away2055Lost connection to MySQL server at stage2026SSL connection error2059Authentication plugin cannot be loaded2061Authentication plugin reported error1251Client doesn't support auth protocol3159Insecure transport prohibited1158Error reading communication packets
The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.
Work on MySQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.