October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk12 min

How to Troubleshoot Common MySQL Problems on Ubuntu Server

Diagnose MySQL on Ubuntu methodically: use systemd and error logs, separate socket from TCP failures, fix permissions and port collisions, configure remote access safely, and verify authentication by host and plugin.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When MySQL fails on Ubuntu, start with evidence rather than repeated restarts. Check the systemd service state and journal, read MySQL’s error log, then test the exact connection path that is failing (Unix socket, TCP, firewall, or account authentication). This sequence separates a stopped server from a bad socket path, a port collision, a filesystem permission error, or an account that is being rejected.

A safe troubleshooting order

Use the following order so that each test narrows the failure without changing more than necessary:

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Confirm whether the service is running and collect its recent messages.
  2. Read the MySQL error log and identify the first fatal message, not merely the last restart attempt.
  3. Classify the failure as startup, configuration, filesystem access, socket/TCP connectivity, firewall, or authentication.
  4. Make the smallest change that addresses the observed error.
  5. Restart once, then verify the journal, listening endpoint, and client connection.

Do not begin by deleting files, changing the root password, opening a firewall port, or running the daemon as root. Those actions can hide the original cause or create a larger security problem.

1. Establish the service state and collect evidence

Check systemd status

Run:

sudo systemctl status mysql

Look for active (running), inactive, or failed. The status output also shows the most recent service messages and the process identifier when MySQL is running. A failed state tells you that startup or a later health check failed; it does not, by itself, explain why.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Ubuntu also supports the traditional service wrapper:

sudo service mysql status

Use one interface consistently while diagnosing. If the service is stopped and you have already captured the evidence, a controlled restart is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo systemctl restart mysql.service

For a first investigation, avoid restarting before reading the existing messages. A restart can replace the most useful context with a second, less informative failure.

Read the systemd journal

sudo journalctl -u mysql

To focus on the current boot and recent events, you can add standard journal filters such as -b or --since. Read from the earliest failure in the sequence: a configuration parse error, permission denial, or bind failure usually appears before the generic “failed to start” line.

The journal is particularly useful when MySQL exits before it can write a normal error-log entry, when the log path is unknown, or when systemd reports a timeout or an unexpected shutdown.

2. Find and read the MySQL error log

MySQL’s error log is the primary explanation for a startup failure. On Debian-family packages, files are commonly under /var/log/mysql, but the active configuration determines the actual location. Do not assume a filename; inspect the configuration and package layout on the affected server.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo ls -la /var/log/mysql
sudo grep -R "^[[:space:]]*log_error" /etc/mysql 2>/dev/null

If the configured value is a relative filename, resolve it against the server’s data or installation layout before opening it. Read the newest entries around the failed start:

sudo tail -n 100 /var/log/mysql/error.log

Substitute the path and filename shown by your configuration. Preserve the first complete error line, including any numeric error code, path, username, address, or port. Those details determine the next branch of the diagnosis.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

3. Classify the startup failure before changing anything

Configuration or syntax errors

A misspelled option, an invalid value, or an option placed in the wrong configuration section can stop MySQL before it opens a socket. The journal and error log commonly identify the option and file. Check every file included by the main configuration, not only the file you last edited.

Undo the single bad change or correct its value, then restart and inspect the same evidence again. Make one configuration change at a time so that the next result is attributable.

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

Errcode: 13 and other permission failures

Errcode: 13 means the server process cannot access a required file or directory. The usual targets are the data directory, its files, the error-log destination, a PID directory, or a Unix-socket directory. The message should identify the path that was denied.

First confirm that the path is the one used by this installation:

sudo grep -R "^[[:space:]]*datadir|^[[:space:]]*socket|^[[:space:]]*pid-file|^[[:space:]]*log_error" /etc/mysql 2>/dev/null
sudo namei -l /path/mentioned/in/the/error

Then verify ownership and mode without changing them blindly:

sudo ls -ld /path/to/data-directory
sudo find /path/to/data-directory -maxdepth 1 -printf '%u:%g %m %pn' | head

The packaged daemon normally runs as the mysql service account. If the confirmed data directory or its contents are owned by an unexpected user, correct ownership only after checking the package’s intended layout and ensuring that no other service uses the files. A typical ownership correction, when you have verified that this is the correct data directory, is:

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.
sudo chown -R mysql:mysql /path/to/data-directory

Do not use recursive ownership changes on an uncertain path, and do not run mysqld as root as a routine workaround. A wrong recursive change can damage a separate instance or backup, while running as root weakens the isolation that protects the server.

Mandatory access controls and parent directories

Traditional Unix permissions are not the only control that can deny access. A mandatory security policy can block a path even when its owner and mode look correct. Check the journal and the system’s security-audit messages for a denial that names MySQL or the affected path. Correct the policy or move the file into the package-supported location rather than disabling the protection globally.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Remember that every parent directory must be traversable by the service account. Checking only the final data directory can miss a denied parent such as a custom mount point.

Port or socket already in use

If the log says Bind on TCP/IP port: Address already in use, another process already owns the configured TCP port. A Unix-socket bind error has the same basic meaning for the socket path: another process, a stale socket, or an incompatible endpoint is blocking creation.

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

Identify listeners before selecting a new port:

sudo ss -ltnp | grep -E 'mysql|3306'
sudo ss -lxnp | grep -E 'mysql|mysqld'

Replace 3306 with the configured port when using a custom value. If another MySQL instance owns the endpoint, determine which configuration and data directory it uses before stopping anything. If an unrelated service owns the port, decide whether that service should move or MySQL should use a different port; record the decision in configuration and firewall rules.

4. Diagnose ERROR 2002 and “Can’t connect through the MySQL socket”

ERROR 2002 is a connection-path error, not a diagnosis. For a client connecting to localhost, MySQL normally attempts a Unix socket rather than TCP. The message can therefore mean that:

  • the server is stopped or failed before creating its socket;
  • the client expects a different socket path from the server;
  • a socket directory is missing or inaccessible;
  • the server is listening only on TCP; or
  • the socket exists but belongs to a different or stale instance.

Check whether the socket exists and matches configuration

sudo grep -R "^[[:space:]]*socket" /etc/mysql 2>/dev/null
sudo ss -lxnp | grep -E 'mysql|mysqld'
sudo find /run /var/run -type s -iname '*mysql*' 2>/dev/null

Compare the client’s expected socket with the server’s configured socket. Specify the confirmed path explicitly for a test:

mysql --socket=/path/to/mysql.sock -u your_user -p

If the service is not running, return to the journal and error log instead of creating an empty socket file. A manually created file cannot make a stopped server accept connections.

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

Force TCP to separate socket and network problems

Use the loopback address rather than localhost:

mysql --host=127.0.0.1 --port=3306 -u your_user -p

If this succeeds while localhost fails, authentication is probably working and the problem is the socket path or socket permissions. If both fail, check the listener and the server log. A successful local TCP test does not prove that remote access is configured; it only proves that the service is reachable through that local address and port.

5. Check the actual TCP listener and bind address

Confirm the port is listening

sudo ss -ltnp | grep -E 'mysql|3306'

An entry such as 127.0.0.1:3306 accepts local loopback connections only. An entry on a server interface address accepts connections arriving at that address. No entry means MySQL did not bind successfully, is listening on another port, or is not running.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Use the configuration that is actually included by this package. On Ubuntu installations, the server settings are commonly in:

/etc/mysql/mysql.conf.d/mysqld.cnf

Check the effective port and bind-address values and any drop-in files that override them. A typo in a drop-in can prevent startup; a valid but unintended bind address can make a healthy server appear unreachable.

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

Choose a bind address deliberately

  • Loopback only: use 127.0.0.1 when applications run on the same server and no remote client should connect.
  • A specific private interface: use the server’s private address when access is needed from a trusted network and you want to avoid exposing other interfaces.
  • All interfaces: a wildcard bind can be appropriate only when firewall rules, account host restrictions, network segmentation, and monitoring are deliberately configured.

Changing bind-address does not grant any user permission and does not open a firewall. It only controls which local addresses accept the TCP connection.

6. Test remote connections, firewall rules, and routing

A remote client needs all of these conditions at the same time:

  • MySQL must be running and listening on the intended port.
  • The bind address must include the server interface reached by the client.
  • Network routing must lead to that interface.
  • A host firewall and any upstream firewall must permit the port.
  • The MySQL account must be allowed from the client’s host.

From the server, verify the listener with ss. From a permitted client, test the port without involving MySQL authentication:

nc -vz server.example 3306

A refused connection usually indicates no listener or an active reject. A timeout points more strongly to a firewall or routing path. Once the TCP test succeeds, test MySQL itself:

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.
mysql --host=server.example --port=3306 -u app_user -p

Open only the chosen port and only to the required source networks. A firewall rule that exposes a database port to every address is a security change, not a troubleshooting shortcut. After changing the port, update every client connection string, monitoring check, firewall rule, and any service discovery entry that still uses the old value.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

7. Resolve “Access denied for user” correctly

An Access denied response proves that a MySQL server answered the connection and rejected the account, credentials, host, or authentication method. It is not evidence that the daemon is stopped. First note the complete error, especially the account shown as 'user'@'host'.

Inspect the account identity and host row

MySQL authorizes an account by its User and Host values. The same username can have different privileges or passwords for localhost, 127.0.0.1, a hostname, and a remote address. Connect with an administrative account that already works and inspect the rows:

SELECT User, Host, plugin FROM mysql.user;

Use the exact host shown in the error when deciding which row applies. Do not create a broad wildcard account merely to make a test pass; create the narrowest host entry that matches the application’s real network path.

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

Understand auth_socket on local root accounts

Ubuntu packages can configure the local root account with the auth_socket plugin. With that arrangement, a matching local system user can authenticate through the Unix socket without entering a MySQL password. A password attempt from a different system user, through TCP, or under a different account can be rejected even when the password seems correct.

Check the plugin before changing credentials. For administration, use the supported local system identity and socket path when that is the intended policy. For an application, create a separate account with only the required privileges and an explicitly chosen authentication method. Avoid weakening root authentication just to accommodate an application connection.

Distinguish wrong credentials from wrong connection path

Test the same account through the path the application uses. A successful socket login does not prove that the TCP account row permits a remote host, and a successful local TCP login does not prove that a remote client’s host value matches the intended account row. Keep the username, host, port, socket, and plugin consistent while testing one variable at a time.

8. Change port or bind-address safely

Before editing

  • Save a copy of the active configuration file or drop-in.
  • Record the current port, bind address, socket path, and data directory.
  • Confirm that no other process owns the proposed port.
  • Plan the firewall and client changes before making the server unavailable.

Apply one change and restart

Edit the intended server configuration, commonly /etc/mysql/mysql.conf.d/mysqld.cnf, and change only the required option under the server section. Then run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo systemctl restart mysql.service
sudo systemctl status mysql
sudo journalctl -u mysql --since "5 minutes ago"
sudo ss -ltnp | grep -E 'mysql|3306'

If the restart fails, the journal and error log identify whether the new value was invalid, the port is occupied, or permissions prevent startup. Restore the last known-good file when necessary, then verify that the original listener returns.

Verify with the client

mysql --host=127.0.0.1 --port=NEW_PORT -u your_user -p

For a remote change, test from an approved client after the local listener check succeeds. Do not assume that a successful restart means the requested address or port took effect; the listener output is the authoritative check of what is bound now.

9. A decision table for common symptoms

Observed symptom Likely failure class First evidence Smallest appropriate next action Verification
systemd reports failed Startup, configuration, permission, or shutdown systemctl status, journalctl -u mysql, error log Fix the first specific error; do not repeat blind restarts Clean restart, status, and journal
Errcode: 13 Filesystem or mandatory security permission Error path, ownership, parent-directory modes, security audit Correct the confirmed path’s access or policy Restart and confirm the log no longer reports denial
Address already in use TCP or Unix-socket collision ss listener output and process owner Stop the correct conflicting instance or choose a documented port Expected process owns the expected endpoint
ERROR 2002 via localhost Socket path, socket permissions, or stopped service Socket configuration, socket listing, service state Start the service or use the confirmed socket path Socket login and explicit TCP test
TCP refused or timed out Listener, bind address, firewall, or routing ss, bind setting, port test from client Correct the listener or the narrowest blocking network rule Port test followed by MySQL login
Access denied Credentials, host row, or authentication plugin Exact 'user'@'host', mysql.user row, plugin Use the intended account/path or correct that account specifically Login through the application’s exact path

10. Recovery practices that prevent a second outage

  • Keep changes reversible. Edit one file, retain the previous version, and record the old and new value.
  • Protect data first. Do not remove redo logs, binary logs, socket files, or data files because a forum command suggests it. Confirm what owns the file and what the error log says before taking a destructive action.
  • Use the package service account. Ownership and execution under mysql preserve the permissions model expected by Ubuntu packages.
  • Separate local and remote tests. A loopback test proves less than a remote test, while a socket test exercises a different path from TCP.
  • Capture the final state. Save the effective port, bind address, socket, service status, listener output, and account host/plugin settings in the server’s runbook.

11. A compact end-to-end checklist

  1. Run sudo systemctl status mysql.
  2. Read sudo journalctl -u mysql and identify the first concrete failure.
  3. Locate the configured error log and read its newest entries.
  4. If the message names a path, verify the data directory, parent directories, ownership, and security controls.
  5. If it names a port or socket, inspect TCP and Unix listeners with ss.
  6. For ERROR 2002, compare the client socket with the server socket, then test 127.0.0.1 and the configured port.
  7. For remote access, verify bind address, routing, firewall, and the port from an approved client.
  8. For Access denied, inspect the exact User, Host, and authentication plugin instead of assuming the service is down.
  9. Restart after the targeted correction.
  10. Verify status, journal, listener, and the same client path that originally failed.

This workflow turns the common Ubuntu/MySQL symptoms into distinct, testable causes: service state, log/configuration, filesystem access, socket versus TCP, firewall, or account authentication. The safest fix is the smallest one supported by the error you can actually see.

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.

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
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.