CertGrid CertGrid
Troubleshooting·MySQL

MySQL Service Management and Startup Failures

Stopping MySQL removes its socket directory, which is why `ERROR 2002` names a file that is not there. Then a bad setting is added on purpose so `mysqld --validate-config` has something real to catch - and the restart it would have prevented fails into a systemd restart loop.

Foundations Guide 5 of 45 Intermediate

Written against the versions above. The unit is named `mysql` on Debian and Ubuntu and `mysqld` on RPM builds. Everything else here is the same.

Every command on this page ran on db-a01.
Server NameIP AddressOSRolesCPURAMHDD
db-a01192.168.0.81Ubuntu 26.04 LTSPrimary / Source / Replica Set Member 12 Core4 GB50 GB

Before you start

  1. Read the service state

    systemctl status in one view: whether the unit is loaded, whether it is enabled, whether it is running, since when, and the last few log lines.

    It is the right first command for a service problem because it answers "is it even trying" before you go looking at MySQL itself.

    bash Example session
    systemctl status mysql --no-pager | head -12● mysql.service - MySQL Community Server     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)     Active: active (running) since Thu 2026-08-27 12:31:42 UTC; 36s ago Invocation: f31dd5aca1e548dd8148c4aa5e4387f0    Process: 8419 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)   Main PID: 8429 (mysqld)     Status: "Server is operational"      Tasks: 40 (limit: 1658)     Memory: 476M (peak: 476.2M)        CPU: 499ms     CGroup: /system.slice/mysql.service             └─8429 /usr/sbin/mysqld

    Expected resultloaded, enabled, and active (running) with a start time.

    Success conditionYou can read the unit's state and recent history in one command.

  2. Read the unit file itself

    systemctl cat prints the unit as systemd sees it, including any drop-ins. Worth doing once so the service stops being a black box.

    Two things to note for later: the unit has a Restart= policy, which is what produces the loop in a few steps' time, and ExecStart runs /usr/sbin/mysqld directly - the same binary you will run by hand to validate the config.

    bash Example session
    systemctl cat mysql | head -22# /usr/lib/systemd/system/mysql.service# MySQL systemd service file [Unit]Description=MySQL Community ServerAfter=network.target [Install]WantedBy=multi-user.target [Service]Type=notifyUser=mysqlGroup=mysqlPermissionsStartOnly=trueExecStartPre=/usr/share/mysql/mysql-systemd-start preExecStart=/usr/sbin/mysqldTimeoutSec=infinityRestart=on-failureRuntimeDirectory=mysqld

    Expected resultThe [Unit], [Service] and [Install] sections of mysql.service.

    Success conditionYou know what the service actually runs and how it behaves on failure.

  3. Stop it, and watch the socket disappear

    Three commands that together explain the most common MySQL error message.

    is-active returns inactive with exit status 3 - systemd's convention for "not running", and a useful thing to test in a script.

    Then the client fails with ERROR 2002 ... (2), and the (2) is ENOENT: no such file. The last command shows why - /var/run/mysqld/ does not exist at all. The directory is created at startup and removed at shutdown, so a missing socket file is not corruption. It is a stopped server.

    bash Example session
    systemctl is-active mysql ; echo "exit=$?"inactiveexit=3sudo mysql -e "SELECT 1" ; echo "exit=$?"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)exit=1ls -l /var/run/mysqld/ ; echo "exit=$?"ls: cannot access '/var/run/mysqld/': No such file or directoryexit=2

    Expected resultinactive with exit 3, ERROR 2002 naming the socket, and No such file or directory.

    Success conditionYou can recognise ERROR 2002 as a stopped server rather than a broken one.

  4. Start it again and validate the configuration

    The server comes back, and then a command worth building a habit around.

    mysqld --validate-config parses every configuration file the server would read and exits without starting anything. exit=0 and no output means the configuration is valid.

    It costs a fraction of a second and it is the difference between finding a typo now and finding it during a restart at the worst possible moment.

    bash Example session
    sudo systemctl start mysqlsystemctl is-active mysqlactivesudo mysqld --validate-config ; echo "exit=$?"exit=0

    Expected resultactive, then exit=0 with no output from the validator.

    Success conditionYou have a way to check a config change before it costs you an outage.

  5. Break it on purpose

    A backup first, then an invalid value appended to the config - innodb_buffer_pool_size = not-a-size. A plausible typo: the setting is real and the value is not.

    --validate-config now prints four errors and exits 1. Read them from the top: the first names the actual problem - an unknown suffix in the value - and the rest are consequences, ending in Aborting.

    This is the whole point of the tool. The server has not been restarted, so it is still running and still serving. Nothing is down.

    bash Example session
    printf 'innodb_buffer_pool_size = not-a-size\n' | sudo tee -a /etc/mysql/mysql.conf.d/mysqld.cnfinnodb_buffer_pool_size = not-a-sizesudo mysqld --validate-config ; echo "exit=$?"2026-08-27T12:32:24.420115Z 0 [ERROR] [MY-000058] [Server] Unknown suffix 'n' used for variable 'innodb-buffer-pool-size' (value 'not-a-size').2026-08-27T12:32:24.420136Z 0 [ERROR] [MY-000077] [Server] /usr/sbin/mysqld: Error while setting value 'not-a-size' to 'innodb-buffer-pool-size'.2026-08-27T12:32:24.420139Z 0 [ERROR] [MY-010746] [Server] Parsing options for plugin 'InnoDB' failed.2026-08-27T12:32:24.420287Z 0 [ERROR] [MY-000067] [Server] unknown variable 'innodb_buffer_pool_size=not-a-size'.2026-08-27T12:32:24.420298Z 0 [ERROR] [MY-010119] [Server] Abortingexit=1

    Expected resultMY-000058 Unknown suffix 'n', three more errors, and exit=1 - with the running server untouched.

    Success conditionYou have seen the validator catch a real error before it caused an outage.

  6. Ignore the warning and restart, which is what usually happens

    What the validator was trying to prevent.

    systemctl restart fails with exit 1 and points at two other commands. Then is-active returns something worse than inactive - activating. The unit's Restart= policy is retrying, and it will keep retrying.

    This state is genuinely confusing in an incident: the service is neither up nor cleanly down, and a monitoring check that only tests inactive will not fire.

    bash Example session
    sudo systemctl restart mysql ; echo "exit=$?"Job for mysql.service failed because the control process exited with error code.See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.exit=1systemctl is-active mysql ; echo "exit=$?"activatingexit=3

    Expected resultJob for mysql.service failed, exit=1, then activating - not inactive.

    Success conditionYou can recognise a restart loop from is-active alone.

  7. Read the journal, then put it back

    journalctl -u mysql is the log for the unit. The restart counter is at 1 and then at 2 lines are the loop, one entry per attempt, with code=exited, status=1/FAILURE between them.

    Note what the journal does not say: it does not name the bad setting. systemd reports that the process exited; the reason lives in MySQL's own error output, which is what --validate-config showed you two steps ago. That is why the validator is the faster path.

    Restoring the backup and validating returns exit=0, and the server starts.

    bash Example session
    sudo journalctl -u mysql -n 8 --no-pagerAug 27 12:32:25 db-a01 systemd[1]: mysql.service: Scheduled restart job, restart counter is at 1.Aug 27 12:32:25 db-a01 systemd[1]: Starting mysql.service - MySQL Community Server...Aug 27 12:32:26 db-a01 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILUREAug 27 12:32:26 db-a01 systemd[1]: mysql.service: Failed with result 'exit-code'.Aug 27 12:32:26 db-a01 systemd[1]: Failed to start mysql.service - MySQL Community Server.Aug 27 12:32:26 db-a01 systemd[1]: mysql.service: Consumed 224ms CPU time over 399ms wall clock time, 245.2M memory peak.Aug 27 12:32:26 db-a01 systemd[1]: mysql.service: Scheduled restart job, restart counter is at 2.Aug 27 12:32:26 db-a01 systemd[1]: Starting mysql.service - MySQL Community Server...sudo cp /tmp/mysqld.cnf.bak /etc/mysql/mysql.conf.d/mysqld.cnfsudo mysqld --validate-config ; echo "exit=$?"exit=0systemctl is-active mysqlactive

    Expected resultRestart counters climbing, then a clean validate and active.

    Success conditionThe server is back, and you know which tool would have caught it first.

Troubleshooting

Official sources