systemctl says Job for mysqld.service failed because the control process exited
Job 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.
Fix it fast
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.log2Match what you see, then jump to its fix
- 1
The 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
The 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
The 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
log-error in the option file points to a path outside /var/log/mysql*.logThe error log path is not writable for mysqldFix
- 1
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_t2Fix
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/datadir3Verify
The service starts and the audit log gets no new denied lines for mysqld.
sudo systemctl start mysqld
systemctl status mysqld.serviceConfirmed by dev.mysql.com
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 mysqld2Fix
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=33073Verify
The service starts, and the error log no longer shows the bind error.
sudo systemctl restart mysqld
sudo tail -n 20 /var/log/mysqld.logConfirmed by dev.mysql.com
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/mysql2Fix
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/mysql3Verify
The service starts and ls -la shows mysql as owner and group.
sudo systemctl start mysqld
ls -la /var/lib/mysqlConfirmed by dev.mysql.com
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-directory2Fix
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.log3Verify
The service starts and new lines appear in that log file.
sudo systemctl start mysqld
sudo tail -n 10 /path/to/my/custom/error.logConfirmed by dev.mysql.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
mysqld.service refuses to start: start request repeated too quickly
systemctl status mysqld shows the unit as failed
This message only says systemd gave up after several failed starts.
3 causes, each with a fixDatabases
MySQL start fails with: the server quit without updating the PID file
Can't start server: Bind on TCP/IP port: Address already in use
This message is only a symptom: mysqld started and exited before it wrote its PID file.
3 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
Locked out of a fresh MariaDB install as root on Mac or Linux
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
A fresh MariaDB root account is not a normal password account.
3 causes, each with a fix