MySQL “Can't connect through socket”: start the server
Start the MySQL server, then confirm the socket path matches between server and client.
Start the server first: brew services start mysql on macOS (Homebrew), sudo systemctl start mysql on Linux. If it is running, the socket path is wrong — find the real one and pass --socket, or set socket in your my.cnf.
Try these fixes in order
Check whether the server runs
If the service is stopped, that is the whole problem.
brew services list | grep mysqlStart the server
Use whichever matches your install: Homebrew services on macOS, systemd on Linux.
brew services start mysqlConfirm the socket path
The server prints the socket path it actually created; compare it with the path in the error.
mysqladmin variables | grep -i socketReconnect and confirm
You should get a mysql> prompt or a version banner instead of ERROR 2002.
mysql -u root -p -e "SELECT VERSION();"Interpret what you see
Fresh boot, or MySQL was installed but never started
What it suggests: This error means no server is listening at that socket; the most common cause is simply that mysqld is not running.
Next check: Check the service status and start it.
The service is running but the client still fails
What it suggests: The server may be running but created its socket elsewhere (for example /var/run/mysqld/mysqld.sock).
Next check: Find the real socket path and pass it with --socket or set it in the config.
The server will not stay running
What it suggests: A crashed server can leave the error log's reason; the log names the actual failure.
Next check: Read the MySQL error log before changing configuration.
Why this happens
- The MySQL server is not running.
- The client is looking for the socket file in a different path than where the server created it.
Still not working?
Do not create a fake socket file or symlink a guess into place; the socket appears when the server starts, and a stale file just moves the failure. Start the server instead.
Official sources
These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.