Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

systemctl says Job for mysqld.service failed because the control process exited

ErrorJob for mysqld.service failed because the control process exited with error code.

Short answer

This systemd message only says mysqld exited at start. The reason is in the MySQL error log, journalctl and the SELinux audit log. Read those first. Then check the four documented causes: a data directory with the wrong SELinux label, a busy port, wrong ownership of the data directory, or an error log path mysqld cannot write.

  • Applies to MySQL 8.4, RHEL-family Linux with systemd and SELinux
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the four places that hold the real reason: the service status, the journal, the MySQL error log (on RPM installs /var/log/mysqld.log unless you changed it) and the SELinux denials.

    systemctl status mysqld.service
    journalctl -xe
    sudo tail -n 30 /var/log/mysqld.log
    sudo grep "denied" /var/log/audit/audit.log
  2. 2Match what you see, then jump to its fix

    1. 1The audit log shows an AVC line with denied, comm="mysqld" and a tcontext such as default_t on the data directoryThe data directory has the wrong SELinux labelFix
    2. 2The error log says Can't start server: Bind on TCP/IP port: Address already in useAnother program already uses the port or the socketFix
    3. 3The error log shows an Errcode 13 (Permission denied) line, and the audit log has no denied lines for mysqldThe data directory belongs to the wrong userFix
    4. 4log-error in the option file points to a path outside /var/log/mysql*.logThe error log path is not writable for mysqldFix

What does the error look like?

  • Job for mysqld.service failed because the control process exited with error code.
  • See "systemctl status mysqld.service" and "journalctl -xe" for details.

Cause 1 of 4

The data directory has the wrong SELinux label

1Check

The default data directory is /var/lib/mysql/ with the SELinux type mysqld_db_t. If you moved the data directory, or its binary logs, the new place needs that type, and starting the service with an invalid context fails with exactly this systemd message. To test the theory without turning SELinux off for the whole system, put only the mysqld_t domain in permissive mode and try again.

sudo semanage permissive -a mysqld_t
sudo systemctl start mysqld
# put it back when the test is finished:
sudo semanage permissive -d mysqld_t

2Fix

Label the new location and apply the label. semanage comes from the policycoreutils-python-utils package on RHEL.

sudo yum install -y policycoreutils-python-utils
sudo semanage fcontext -a -t mysqld_db_t "/path/to/my/custom/datadir(/.*)?"
sudo restorecon -Rv /path/to/my/custom/datadir

3Verify

The service starts and the audit log gets no new denied lines for mysqld.

sudo systemctl start mysqld
systemctl status mysqld.service

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 4

Another program already uses the port or the socket

1Check

MySQL's manual says to look for another mysqld that is already running, and if there is none, to find out which program holds the port. Port 3306 is the default.

ps aux | grep mysqld

2Fix

Stop the other server or the program that owns the port, or tell mysqld to listen on a different port in the option file.

# /etc/my.cnf
[mysqld]
port=3307

3Verify

The service starts, and the error log no longer shows the bind error.

sudo systemctl restart mysqld
sudo tail -n 20 /var/log/mysqld.log

Confirmed by dev.mysql.com

Did this fix it?

Cause 3 of 4

The data directory belongs to the wrong user

1Check

Errcode 13 means the privileges of the data directory or its contents do not let the server in. Look at the owner and group of the directory and the files inside it.

ls -la /var/lib/mysql

2Fix

Give the directory and everything in it to the mysql user and group. The manual notes that starting the server as root would also work but raises security issues and should be avoided.

sudo chown -R mysql /var/lib/mysql
sudo chgrp -R mysql /var/lib/mysql

3Verify

The service starts and ls -la shows mysql as owner and group.

sudo systemctl start mysqld
ls -la /var/lib/mysql

Confirmed by dev.mysql.com

Did this fix it?

Cause 4 of 4

The error log path is not writable for mysqld

1Check

The helper script that the unit file runs creates the error log only when its path matches /var/log/mysql*.log. For any other path, the directory must be writable, or the file must already exist and be writable, for the user that runs mysqld.

grep -n "log-error" /etc/my.cnf
ls -ld /path/to/log-directory

2Fix

Create the file and give it to the mysql user. If the path is a custom one, also give it the SELinux type mysqld_log_t.

sudo touch /path/to/my/custom/error.log
sudo chown mysql:mysql /path/to/my/custom/error.log
sudo semanage fcontext -a -t mysqld_log_t "/path/to/my/custom/error.log"
sudo restorecon -Rv /path/to/my/custom/error.log

3Verify

The service starts and new lines appear in that log file.

sudo systemctl start mysqld
sudo tail -n 10 /path/to/my/custom/error.log

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • After you move a data directory or a log file, label it with semanage and restorecon in the same change.
  • Keep the error log at the default path unless you have a reason to move it.
  • Start the service once by hand after every config change and read journalctl before you close the terminal.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.