The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
The error is usually fixed by starting the MySQL server and making the client use the same Unix-socket pathname as the server. If you prefer TCP/IP, connect to 127.0.0.1 on the instance’s configured port instead of using localhost; that works only when TCP/IP is enabled and reachable.
What the error means
On Unix-like systems, MySQL has two local connection transports:
- Unix socket: a special file, such as
/tmp/mysql.sock, used when the client is given no host or is givenlocalhost. - TCP/IP: a network connection to an address and port, commonly
127.0.0.1:3306.
Oracle’s MySQL 8.4 Reference Manual describes the distinction this way: “A MySQL client on Unix can connect to the mysqld server in two different ways: By using a Unix socket file to connect through a file in the file system (default /tmp/mysql.sock), or by using TCP/IP, which connects through a port number.”
Therefore, “Can’t connect to local MySQL server through socket” (often reported as error 2002) means the client could not open the local socket connection it attempted. It does not, by itself, mean that the username or password is incorrect. Authentication is reached only after a transport connection succeeds.
#1 Best Overall
Choose the right branch first
| What you observe | Most useful next action | Reason |
|---|---|---|
| The MySQL service is stopped or repeatedly exits | Start or repair mysqld, then read its error log |
No socket or TCP connection can succeed while the server is down. |
| The error names a socket path that does not exist | Find the server’s actual socket and pass it with --socket |
The client and server must use exactly the same pathname. |
| The socket exists but the client gets “permission denied” | Check permissions on the socket and every directory in its path | Both the client process and the server’s service account need appropriate filesystem access. |
| The socket is in a temporary directory and disappears after reboot or cleanup | Prevent cleanup from deleting it or move it to a persistent socket directory | A live socket can be removed even though the server process was started. |
| You intentionally want TCP/IP | Use -h 127.0.0.1 -P with the configured port |
An IPv4 loopback address selects TCP rather than the localhost socket convention. |
1. Confirm that the MySQL server is running
The socket file is created by the running server. If mysqld never started, the client’s socket error is only a symptom of that earlier failure.
Check the service manager
On a system using systemd, check the service name used by your package:
sudo systemctl status mysql
sudo systemctl status mysqld
Only one of those names may exist. A package using the traditional service interface can be checked with:
sudo service mysql status
Look for an active (running) state. If the service is inactive, start it and immediately check its status again:
sudo systemctl start mysql
sudo systemctl status mysql
Use the service name that your installation actually provides; do not start a second instance simply because the first name returned “unit not found.”
Check for a running process
If you do not know which service name was installed, inspect the process list:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →ps -ef | grep '[m]ysqld'
A process listing is evidence that a process exists, not that it is healthy or listening on the expected socket. A process that starts and exits can leave you with no usable endpoint, so inspect the service’s startup output and MySQL error log when the state is failed.
Read the startup failure before changing client settings
The error log is the authoritative place to look for a failed data directory, invalid option, unavailable port, damaged files, or a permission problem during startup. Its exact location depends on the package and configuration. Read the path shown by the service manager or the configured log_error setting rather than assuming every distribution uses the same file.
Do not try to solve a stopped server by changing a password. A password is evaluated after a connection reaches MySQL; it cannot make a missing server create a socket.
2. Read the socket pathname in the error literally
The text after socket is the pathname that this client tried to open. Copy it exactly, including capitalization and every directory component. For example, an error naming /tmp/mysql.sock is not satisfied by a socket at /var/lib/mysql/mysql.sock.
/tmp/mysql.sock is a documented general default, but distribution packages and separately installed instances commonly choose another location. Paths under /var/lib/mysql, /run, or a package-specific runtime directory are possible. There is no universal pathname that can safely be substituted for the one configured by your instance.
Look for an existing Unix socket
On Linux, a targeted search can reveal candidate socket files:
sudo find /run /var/run /tmp /var/lib/mysql -type s -name 'mysql.sock' 2>/dev/null
The command may return several paths if more than one MySQL-compatible instance is installed. Match the result to the instance you intend to use; selecting a socket belonging to another server can produce a different username, database, or port than expected.
If no socket is found, return to the service status and error log. A missing file usually means the server did not create it, created it somewhere else, or it was removed after creation.
Recommended Free Tools
3. Make the client and server use the same socket
When the server uses a custom socket, every client that connects through it must be told the new name. Test the path explicitly instead of relying on a stale option file:
mysql --socket=/path/to/mysql.sock -u USER -p
The administrative client can be tested the same way:
mysqladmin --protocol=SOCKET --socket=/tmp/mysql.sock version
Replace the example paths with the path configured for your running instance. A successful mysqladmin ... version response confirms that the socket transport works independently of the SQL client’s default options.
Inspect the server configuration
Find the active MySQL option file and inspect the [mysqld] section for a socket setting. The effective value may come from a package-managed file, an included directory, a command-line option, or a custom instance configuration. The value that matters is the one used when this server started.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteThen inspect the client sections, commonly [client] and [mysql], for a different socket value. A client option file pointing to an old installation is a frequent reason that the server is healthy while a plain mysql -u USER -p command still fails.
Make the correction persistent
For a long-term fix, either change the client configuration to the server’s established path or deliberately configure both sides to a new path. Restart the server after changing its socket option, then verify the resulting file and test with an explicit --socket argument before removing the command-line override. Changing only one side guarantees a mismatch.
If several MySQL instances run on the same host, give each instance its own socket path and keep each service’s client configuration separate. Do not point all clients at whichever mysql.sock happens to be found first.
4. Check permissions on the entire socket path
A Unix socket is subject to ordinary filesystem access checks. The connecting user needs permission to traverse every directory in the path and to access the socket itself. The server account also needs permission to create and maintain the socket in its parent directory.
Inspect the path components
Use a long listing for the socket and each parent directory:
ls -ld /path /path/to /path/to/mysql.sock
Check the owner, group, and mode bits. A directory can appear readable while lacking the execute permission required to traverse it. Conversely, a socket can have permissive mode bits while a parent directory blocks access.
Rank #4
Apply a targeted fix
Correct ownership or group membership for the intended service account and connecting users, or choose a socket directory designed for both processes. Keep the change narrow: broad commands such as making the entire data directory world-writable can create a security problem and are not required to fix a socket mismatch.
After changing access, reconnect as the same operating-system user that failed. Testing only as root can hide a permission problem that application users will continue to experience.
Free tools Windows power users keep installed
One-click scans. No signup required.
5. Check whether cleanup removed the socket
Sockets placed directly in temporary directories can be deleted by reboot cleanup, scheduled housekeeping, or a temporary-file policy. The server process may still exist, but clients then receive a “no such file” socket error because the endpoint has vanished.
Protect or relocate the socket
MySQL’s socket-protection guidance recommends preventing cleanup from deleting a live socket or moving it to a safer, dedicated location. If you keep the socket under /tmp, ensure that the directory’s normal sticky-bit protection and cleanup policy do not remove the file while the instance is running. A persistent runtime directory managed for the service is generally easier to control than an arbitrary temporary path.
After changing the location, restart the instance, confirm that the new socket is created, and update every client configuration that used the old path.
6. Test TCP/IP deliberately with 127.0.0.1
To bypass Unix-socket selection, specify the loopback address and the instance’s TCP port:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsmysql -h 127.0.0.1 -P 3306 -u USER -p
3306 is MySQL’s documented default port, not a guarantee that your instance uses it. Substitute the port configured for this server. Using 127.0.0.1 selects IPv4 TCP/IP; it does not repair a stopped server or a server that accepts only socket connections.
Understand why the TCP test can fail
skip_networking: disables TCP/IP for the server. In that configuration, a socket connection is required.bind_address: limits which local or network addresses the server listens on. A server bound elsewhere may not accept connections addressed to127.0.0.1.- Firewall rules: can block the selected port even when the server is running and configured for TCP.
- Wrong port: a different MySQL instance or custom port may be listening, so test the configured value rather than assuming
3306.
Verify that something is listening
On Linux, you can inspect listening TCP sockets with:
sudo ss -ltnp | grep 3306
If the configured port is not 3306, replace the number in the command. No listening entry means the server may have TCP disabled, may be bound to another address, may not be running, or may be using a different port. A listening entry does not by itself prove that a firewall or account policy will permit the login, but it distinguishes “no TCP endpoint” from a later authentication failure.
Best Value
7. Distinguish transport errors from authentication errors
A socket error occurs while the client is opening the local transport. The server has not yet accepted the session, so changing the MySQL password or grants does not address a missing socket, wrong pathname, stopped service, or inaccessible directory.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
An Access denied response is different: it indicates that the connection reached MySQL and the next problem is account authentication or authorization. Once you see that response, stop changing socket paths and investigate the account name, password, authentication method, host pattern, or privileges instead.
Common scenarios and their fixes
The service is active, but the default client still reports a missing socket
Find the socket created by the running instance and compare it with the path printed by the error. If they differ, use --socket for an immediate test, then correct the client option file so future commands select the same path.
The error names /tmp/mysql.sock, but another path exists
This is a client/server pathname mismatch, not proof that MySQL is broken. Connect with the existing path, or intentionally reconfigure the server and all clients to use /tmp/mysql.sock. Do not create an empty file at the error path; a regular file is not a functioning MySQL socket.
The socket exists, but only one user can connect
Compare the successful and failing operating-system users. Inspect every parent directory and the socket’s owner, group, and mode. Grant the minimum required access to the application account or place the socket in a directory whose ownership and group policy match the intended clients.
The problem returns after reboot
Check whether the service starts automatically, whether startup creates the socket in a runtime directory, and whether a cleanup job removes it. A persistent service configuration and a protected socket directory prevent a temporary workaround from becoming a recurring outage.
The socket works, but the TCP command fails
Check the server’s skip_networking, bind_address, and port settings, then inspect the host firewall. A working Unix socket proves only that local file-based transport is available; it says nothing about TCP listeners.
The TCP command works, but localhost fails
This is expected when localhost selects a Unix socket whose path is wrong or inaccessible. Continue using the loopback TCP command if that is an intentional policy, or fix the socket configuration so both connection styles reach the same instance as designed.
Quick Recap
A repeatable recovery procedure
- Copy the socket pathname and any error number from the client message.
- Check the MySQL service state and process list.
- If startup failed, read the MySQL error log and repair that failure before testing clients.
- Locate the socket created by the intended instance and compare it character-for-character with the client’s attempted path.
- Run
mysql --socket=/actual/path/mysql.sock -u USER -pto test the transport explicitly. - If that fails, inspect permissions on the socket and every parent directory for the connecting user and the service account.
- Check whether temporary-file cleanup removed the socket and move or protect it if necessary.
- If TCP is acceptable, run
mysql -h 127.0.0.1 -P CONFIGURED_PORT -u USER -p. - If TCP fails, check
skip_networking,bind_address, the actual port, and firewall rules. - Once one method works, make its path and protocol settings persistent in the appropriate service and client configuration, then retest using the application’s real operating-system account.
Prevent the error from returning
- Document the socket pathname and TCP port for each MySQL instance on the host.
- Keep server and client option files synchronized whenever the socket location changes.
- Use a dedicated, protected runtime directory instead of an unmonitored temporary location when the package permits it.
- Monitor service restarts and inspect the error log when startup fails.
- For applications, choose one deliberate transport: a configured Unix socket for local-only access or TCP/IP with an explicit address and port.
- Test with the same user and environment used by the application, not only with an administrator account.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

