Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
VGSOURCES
Get listed

Database administrationPATCH 2026.10.16

How to Fix MySQL Error 2002 and the Missing mysqld.sock

By VGSources Team 10 min read

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Error 2002 means the MySQL client cannot reach a local server through the Unix socket it selected. The usual causes are a stopped or crashed mysqld, a client and server configured with different socket paths, or permissions that prevent access to the socket directory or file. Start by checking the service, then compare the exact socket path in the error with the server’s configured value. If needed, test TCP/IP separately to determine whether the server works while the socket path is wrong.

MySQL documents Error 2002 as either a server-availability problem or an incorrect Unix-socket filename or TCP/IP port. See the MySQL connection troubleshooting reference while working through the checks below.

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What Error 2002 actually means

A typical message looks like this:

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

The mysql client attempted a local connection, chose a Unix-domain socket, and failed before authentication. Error 2002 is therefore not, by itself, a bad-password or account-privilege error. The failure is between the client and the server endpoint.

According to the Oracle MySQL Reference Manual, the normal explanations are that no local MySQL server is running or that the client is using the wrong Unix-socket filename or TCP/IP port. The same reference also lists a socket removed from its directory, a server started with a different --socket value, crashed server threads, and insufficient permissions on the socket directory or file.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses | Anti UV Ray, For Computers & Gaming, Square Frame, Eyewear for Men and Women
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

On Unix systems, omitting a host or using localhost normally selects a Unix socket. An explicit TCP/IP host and port use a different transport. That distinction makes a TCP test a useful diagnostic rather than merely an alternative way to log in.

Read the path and error code before changing anything

Copy the complete socket path from the error message. A path such as /var/run/mysqld/mysqld.sock or /tmp/mysql.sock tells you where the client looked; it does not prove that the server is configured to create its socket there.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Error code (2): the client generally found no socket at the path it checked. The daemon may be stopped, may be using another path, or may be unable to create the file.
  • Error code (111): the endpoint rejected the connection. This can occur when the server is not accepting connections at that socket, even if a file exists.
  • A different path than expected: treat the discrepancy as evidence of separate client and server settings, not as a reason to create an empty file manually.

The socket is a special operating-system endpoint created by mysqld. Touching a regular file with the same name cannot make it a working MySQL socket.

Use this troubleshooting order

Work from server availability toward path, permissions, and transport. This order prevents you from editing client options while the daemon is simply stopped.

  1. Inspect the MySQL service with the service manager and start the unit that exists on your distribution.
  2. If startup fails, read the MySQL error log and fix the startup or crash cause before troubleshooting the client path.
  3. Check whether the socket file exists at the path shown in the error and at any path configured for the server.
  4. Make the server’s --socket value and the client’s --socket value identical.
  5. Verify that the daemon can create the socket and that the client account can traverse its directory and access the file.
  6. Run an explicit TCP/IP test on the same host. A successful TCP test isolates the problem to the Unix-socket path or its permissions.
  7. If the socket repeatedly disappears, investigate cleanup jobs and recurring daemon crashes.

1. Check whether mysqld is running

MySQL’s documented troubleshooting sequence begins with server availability. Service-unit names vary by operating system and package, so check the names installed on your machine rather than assuming one universal name. These examples inspect the two common unit names:

sudo systemctl status mysql
sudo systemctl status mysqld

Use the unit that exists and reports the MySQL server. If it is stopped, start that unit:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
sudo systemctl start mysql

If your installation uses the mysqld unit instead, substitute that name:

sudo systemctl start mysqld

After starting the service, retry the original mysql command. If the service immediately stops or the start operation reports an error, do not keep retrying the client. The daemon’s error log is the next source of evidence; startup failures and crashes must be resolved at the server before a socket can remain available.

The exact unit name and default socket location depend on the operating system and package. A status result for the wrong unit can mislead you into thinking MySQL is absent or stopped, so confirm which unit your installation actually provides.

2. Inspect the socket locations

Check the path printed by the error and the documented default location:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ls -l /tmp/mysql.sock /var/run/mysqld/mysqld.sock 2>/dev/null

MySQL documents /tmp/mysql.sock as a default Unix-socket location, while packaged Linux installations often configure another directory. The command above is an inspection only: it does not create, repair, or replace a socket.

Interpret the result together with service status:

  • If mysqld is stopped, the missing file is an effect of the stopped server. Start or repair the service first.
  • If the server is running and one of the paths exists, compare that path with the one in the error. The client may be looking at a stale or different setting.
  • If the server is running but neither path exists, check the server’s configured --socket value, its error log, and its ability to write to the socket directory.
  • If a socket exists but the client receives a refusal, the server may not be accepting connections there, or the file may no longer belong to the active daemon.

3. Make server and client socket settings match

The server chooses its Unix-socket filename through the --socket option, supplied directly on its command line or through an option file. The client can choose a socket with its own --socket option or through the client options in an option file. Both sides must use the same path.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men | Office Gifts for Women, iPhone Stand, Gadgets for Men, Office Decor, Gaming Desk Accessories for Samsung Fold 8, Switch, iPad
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

For example, if the server is configured to create /tmp/mysql.sock but the client error names /var/run/mysqld/mysqld.sock, change the client selection to the server’s actual path or change the server configuration and restart it. Do not guess which side is wrong: establish the server value from the active service configuration or startup information, then set the client to that exact value.

You can test a known path without changing persistent configuration:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mysqladmin --protocol=SOCKET --socket=/path/to/mysql.sock version

Replace /path/to/mysql.sock with the path created by your running server. A successful response confirms that the client can reach a server through that socket. A failure leaves the service, permissions, and path checks still in scope.

When making a permanent change, keep the server and client settings synchronized. A server restart may be required after changing the server’s option, while a client-side option takes effect for subsequent connections. If multiple client programs are used, make sure each one reads the same intended client socket setting; fixing only one command can leave other applications pointed at the old path.

4. Correct directory and socket permissions

The account running mysqld must be able to create the socket in its directory. The account running the client must be able to traverse that directory and access the socket file. A healthy daemon can therefore still produce Error 2002 when directory ownership, group membership, or mode bits block either operation.

Check the directory as well as the file shown by ls -l. A socket file that is present but inaccessible is not fixed by changing the client path. Correct the ownership, group, or mode according to your installation’s security policy, or configure the socket in a directory where the daemon has creation rights and authorized clients have access.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Do not create a random empty file with the socket’s name. A Unix socket is created by the server process; replacing it with a regular file removes the endpoint the client needs. If the directory itself is missing, determine why the service did not create it and use the service’s documented directory setup rather than improvising a world-writable location.

5. Use TCP/IP to separate a socket problem from a server problem

Unix sockets are local-only. On the same host, force the client to use TCP/IP and specify the server address and port:

mysql --protocol=TCP --host=127.0.0.1 --port=3306 -u USER -p

Replace USER with the account you intend to use and enter its password when prompted. Port 3306 is MySQL’s default, but your server may be configured for another port; verify the configured value before treating a failed test as proof that the daemon is down.

Interpret the comparison:

  • TCP succeeds while the socket command fails: the server is reachable over TCP, so concentrate on the Unix-socket path, client options, directory permissions, or a process that removes the socket.
  • Both TCP and socket connections fail: investigate service state, startup or crash errors, the configured port, and server-side availability.
  • TCP fails with a remote host: check that the server is listening on the intended address and port and that a firewall or other port block is not preventing access.

Using 127.0.0.1 and --protocol=TCP deliberately avoids the Unix behavior in which localhost selects a socket. This makes the test meaningful even when the default socket path is broken.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

6. Investigate a socket that keeps disappearing

If the service is healthy and the path is correct but the socket vanishes later, look for maintenance tasks that remove files from the socket directory. MySQL specifically notes that a cron job or cleanup process can delete a socket located in /tmp.

Change the cleanup policy so it does not remove the active socket, or configure the server to use a protected directory with appropriate ownership and permissions. After making that change, restart the server if required so it creates a socket at the new location, then update every client that needs to connect locally.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

A disappearing socket can also indicate that mysqld crashed and left no replacement endpoint. Review the MySQL error log for the crash or startup cause and resolve that underlying problem. Recreating the path without fixing repeated daemon failure only produces another temporary outage.

7. Local versus remote connections

A Unix socket is a file on one machine, so it cannot connect to a MySQL server on another host. For a remote database, use TCP/IP with the remote host and configured port. Socket troubleshooting applies only when the client and server are on the same operating-system instance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For remote failures, include network checks in addition to MySQL checks: confirm the server’s listening address and port, verify the configured port rather than assuming 3306, and check firewalls or other port-blocking controls. A local socket path on the client cannot be repaired to reach a remote daemon.

Decision table: choose the remedy that matches the evidence

Observed condition Transport or scope Most likely focus Next action
Service is stopped Local Unix socket Server availability Start the installed MySQL unit and inspect the error log if startup fails.
Service starts, but the client names a different path Local Unix socket Server/client option mismatch Use the server’s active --socket value in the client.
Socket exists but access is denied Local Unix socket Directory or file permissions Correct ownership, group, or mode for the daemon and client accounts.
TCP to the same host succeeds TCP/IP versus Unix socket Socket path or permissions Repair the Unix-socket configuration; the server is reachable over TCP.
Socket disappears after cleanup runs Local Unix socket File-removal policy Exclude the active socket directory from cleanup or move the socket to a protected directory.
Remote host cannot be reached Remote TCP/IP Port, listening address, or firewall Verify the configured port and network access; a local socket cannot be used remotely.

Complete recovery playbooks

When the server is simply stopped

  1. Run sudo systemctl status mysql and, if necessary, sudo systemctl status mysqld to identify the installed unit.
  2. Start the unit that exists with sudo systemctl start UNIT, substituting its actual name.
  3. Retry the original client command.
  4. If the unit fails to start, stop changing client settings and inspect the MySQL error log for the server-side cause.

When the server is running at another socket path

  1. Record the exact path in the Error 2002 message.
  2. Establish the path configured for the running server’s --socket option.
  3. Inspect candidate paths with ls -l.
  4. Test the confirmed path using mysqladmin --protocol=SOCKET --socket=/confirmed/path version.
  5. Update the client option or server option so both use that same path, then restart the server if its setting changed.

When TCP works but the socket does not

  1. Run the explicit TCP test against the configured local port.
  2. Confirm that the daemon is accepting TCP connections.
  3. Focus on the Unix-socket directory, file permissions, cleanup jobs, and client --socket settings.
  4. Retest the socket with mysqladmin after each correction.

When the daemon repeatedly crashes

  1. Check service status immediately after the failure.
  2. Read the MySQL error log rather than assuming the socket path is the root cause.
  3. Resolve the startup or crash condition so the daemon remains running.
  4. Only then validate the socket path and client permissions.

Common mistakes that prolong Error 2002

  • Assuming localhost means TCP: on Unix it normally selects a socket. Use --protocol=TCP --host=127.0.0.1 when you need a TCP diagnostic.
  • Assuming 3306 without verification: it is the default port, not a guarantee about your server’s configuration.
  • Checking only the file: the parent directory’s traversal and creation permissions matter just as much.
  • Creating a placeholder socket file: only the running server can create a functioning Unix socket.
  • Editing only one client configuration: other programs may continue using an old client socket value.
  • Blaming the client after a crash: a crashed or stopped daemon cannot provide a socket, regardless of the path in the command.
  • Using a local socket for a remote server: sockets do not cross hosts; remote connections require TCP/IP and network access.

What a successful fix looks like

The repair is complete when the MySQL service remains running, the server creates a socket at the path you intend to use, the client selects that same path, and the relevant accounts can access the directory and socket. A direct mysqladmin --protocol=SOCKET --socket=... check should reach the server, while an explicit TCP test should use the configured port when that transport is required.

Keep the exact service unit, socket path, and port documented for your installation. Package defaults differ, and a future cleanup-policy change, permission change, or daemon crash can recreate Error 2002 even though the client command has not changed.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Database administrationERROR 2002Linux troubleshootingMySQLmysqld.sockUnix sockets

Leave a reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.