Recommended Free Tools
A failed systemctl start mysqld command is only a symptom. The reliable fix is to capture the unit’s journal and MySQL error log, identify the resource that failed (data directory, log, socket, or port), correct only that resource, and then verify a fresh start. On CentOS, the package may install a unit named mysqld, mariadb, or a version-specific service, and SELinux can block a configuration that looks correct under ordinary Unix permissions.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
Start with evidence, not repeated restarts
Do not begin by deleting files, changing every permission to world-writable, disabling SELinux, or launching the daemon as root. Each of those actions can destroy useful evidence or create a security and data-integrity problem. Preserve the first failure, then make the smallest correction supported by the logs.
As an Amazon Associate I earn from qualifying purchases.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Identify the installed service unit
The command in many Oracle MySQL packages is mysqld; MariaDB commonly uses mariadb. Software Collections and vendor packages can use another name. Find the installed unit before substituting commands:
systemctl list-unit-files --type=service | grep -Ei 'mysql|maria'
systemctl list-units --type=service --all | grep -Ei 'mysql|maria'
rpm -qa | grep -Ei 'mysql|mariadb'
Use the unit that actually exists in every later command. In the examples below, mysqld means “the installed MySQL-compatible service”; replace it with mariadb or the discovered name when necessary.
#1 Best Overall
Capture status and the last journal entries
Run these commands before attempting another start. Save their output in a root-owned diagnostic file or a terminal transcript so you can compare it after the repair.
sudo systemctl status mysqld --no-pager -l
sudo journalctl -u mysqld -n 100 --no-pager
sudo journalctl -xe
systemctl status often reports only “Job for mysqld.service failed because the control process exited with error code.” That line does not identify the cause. The unit-specific journal normally contains a more useful message. The -xe view is useful when systemd directs you to it, but filter by the service so unrelated boot messages do not distract you.
Read the MySQL error log and active configuration
Oracle MySQL’s troubleshooting guidance is direct: check the error log to see why the server does not start. Read the newest lines first; they usually contain the fatal error immediately before shutdown.
Find the configured error log
Common locations include a file under /var/log or a file inside the data directory, but do not assume either path. Inspect the effective configuration and the unit definition:
sudo systemctl cat mysqld
sudo my_print_defaults mysqld 2>/dev/null
sudo grep -RniE '^(datadir|log[-_]error|socket|port)' /etc/my.cnf /etc/my.cnf.d 2>/dev/null
Then read the path named by log-error (or its package-specific equivalent):
sudo tail -n 100 /path/to/mysql-error.log
If the configured log is inside a custom directory, check that directory as well as the file. A daemon can fail because it cannot create the log even when the data directory is usable. If no file is being written, the journal may contain the startup diagnostics instead.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteRank #2
Confirm every path and option that affects startup
Record the active values for:
datadir: the directory containing the system tables and databases.socket: the Unix-domain socket used by local clients.port: the TCP listener; MySQL’s documented default is3306.log-errorand any PID-file location.
MySQL uses the data directory as its working location for databases, logs, and the PID file unless separate paths are configured. A typo, an unmounted filesystem, or a directory that was moved without updating the configuration can therefore stop startup before networking is involved.
Fix a missing or inaccessible data directory
Check that the filesystem and directory exist
sudo findmnt -T /path/to/datadir
sudo ls -ld /path/to/datadir
sudo ls -la /path/to/datadir | head -n 30
sudo namei -l /path/to/datadir
findmnt shows which filesystem supplies the path and helps expose an unmounted volume. namei -l displays permissions on every parent directory; the MySQL account needs execute (“search”) permission through each parent, not just read and write permission on the final directory. If a mount is absent, mount the intended filesystem using your normal system procedure and confirm that the expected database files are present. Do not initialize a new empty data directory over an existing database.
Verify the service account and ownership
Determine the account configured by the unit:
sudo systemctl show mysqld -p User -p Group
getent passwd mysql
getent group mysql
Most packages use the mysql user and group, but use the values reported by the unit. Check ownership recursively before changing it:
sudo stat -c '%U:%G %a %n' /path/to/datadir
sudo find /path/to/datadir -maxdepth 2 -printf '%u:%g %m %pn' | head -n 50
The MySQL documentation states that ownership and permissions of the data directory and its contents must allow the server to read and modify them. If the error log reports Errcode 13, that means “Permission denied”: the data directory or one of its contents does not permit server access.
For a directory intentionally dedicated to this service, correct ownership to the service account shown above:
sudo chown -R mysql:mysql /path/to/datadir
Use the actual account and group if they differ. Preserve restrictive, package-appropriate modes; do not solve the problem with chmod -R 777. Also inspect the configured error-log directory, socket parent, and PID-file parent. They must be searchable and writable where the daemon needs to create files, while unrelated users should not gain write access.
Do not run mysqld as root as a routine fix
Starting the server manually as root may make one permission error disappear while leaving files owned by root and creating a more serious security problem on the next normal start. Stop that experiment, restore ownership to the configured service account, and diagnose the original denial instead.
Account for SELinux when Unix permissions look correct
On SELinux-enabled CentOS and other RHEL-family systems, a path can be owned by mysql:mysql and still be denied. SELinux checks the security context in addition to ordinary mode bits. This is especially common after moving /var/lib/mysql, placing logs on another volume, or selecting a non-default TCP port.
Determine enforcement and collect the denial
getenforce
sudo ausearch -m avc -ts recent
sudo grep "denied" /var/log/audit/audit.log | tail -n 50
Look for an AVC denial at the same time as the failed start. Keep the exact path, operation, and target type; they tell you whether the blocked resource is a database file, log, socket, or network bind. Do not leave the machine in permissive mode as a permanent workaround. If you temporarily changed enforcement while testing, restore the previous enforcing policy after collecting evidence.
Label a custom data directory persistently
The default MySQL data directory is /var/lib/mysql/, and the documented SELinux type for database files is mysqld_db_t. Inspect the current labels and the policy’s known MySQL paths:
sudo ls -Zd /var/lib/mysql /path/to/datadir
sudo semanage fcontext -l | grep -i mysql
For a custom location, add a persistent file-context rule for the directory and its contents, then apply it:
sudo semanage fcontext -a -t mysqld_db_t '/path/to/datadir(/.*)?'
sudo restorecon -Rv /path/to/datadir
If a rule already exists, modify the existing rule rather than creating a duplicate. The semanage command may be supplied by the distribution’s SELinux policy-management package. After relabeling, recheck with ls -Zd and compare a sample file’s context with the default tree. Apply the same evidence-first approach to custom log, socket, or PID locations: use the context expected by the installed policy instead of guessing a type.
Rank #4
Permit a non-default MySQL port
A changed port has two independent requirements: no other process may already own it, and SELinux must allow MySQL to bind it. MySQL documents that selecting a port such as 3307 without updating policy can produce an AVC name_bind denial and prevent startup.
Inspect the port labels and add the configured port to the MySQL port type when policy does not already contain it:
sudo semanage port -l | grep mysqld_port_t
sudo semanage port -a -t mysqld_port_t -p tcp 3307
Replace 3307 with the actual configured port. If the port is already listed, do not add a duplicate; verify that it is associated with mysqld_port_t. A policy change should be based on the AVC and the installed distribution policy, not on disabling SELinux globally.
Rule out a port, socket, or duplicate-process conflict
Check the configured TCP port
MySQL’s default TCP port is 3306. Check that port or the value found in the active configuration:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemssudo ss -ltnp | grep ':3306'
sudo lsof -nP -iTCP:3306 -sTCP:LISTEN
Replace 3306 with the configured number. An “address already in use” message means another listener owns the address. Identify the process from ss or lsof before stopping anything. It may be an already-running MySQL instance, MariaDB, a container, a test daemon, or an unrelated service. Stop or reconfigure only the process you have positively identified; never kill a database process blindly.
Look for a second mysqld instance
ps -ef | grep '[m]ysqld'
sudo systemctl list-units --type=service --all | grep -Ei 'mysql|maria'
If a manually started server is running outside systemd, its PID file, socket, and port can block the packaged unit. Determine its data directory and configuration first, then shut it down through the appropriate control method. A forced kill can cause recovery work and should be a last resort after a graceful stop has failed.
Best Value
Check the Unix socket path
Two local servers can use different TCP ports yet still conflict over one Unix socket. Find the configured socket and inspect its parent:
sudo grep -RniE '^[[:space:]]*socket[[:space:]]*=' /etc/my.cnf /etc/my.cnf.d 2>/dev/null
sudo ls -l /path/to/mysql.sock
sudo ss -xl | grep -i mysql
The error log may say “Can’t create UNIX socket” or “Address already in use.” Remove a stale socket only after confirming that no live process owns it; deleting a socket belonging to a running server disrupts clients. If the parent directory was moved or recreated, give the service account the required access and apply the appropriate SELinux context.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use the error message to choose the narrow correction
| Observed evidence | Resource involved | What to verify | Narrow correction |
|---|---|---|---|
Errcode 13 or “Permission denied” while opening database files |
Data directory or a parent path | Service account ownership, mode bits, parent traversal, SELinux AVC | Correct ownership and restrictive permissions; label a custom path persistently |
| “Can’t open error log” or failure creating a PID file | Log or PID-file directory | Configured path exists; service account can create the file; context is valid | Create or repair only the required directory and its ownership/context |
| “Bind on TCP/IP port” or “Address already in use” | Configured TCP port | ss/lsof owner; duplicate server; SELinux name_bind AVC |
Stop/reconfigure the identified listener or permit the port in SELinux policy |
| “Can’t create UNIX socket” or socket address in use | Unix socket or its parent | Live process using the socket; stale file; parent access and context | Gracefully stop the conflicting server or remove only a confirmed stale socket |
“No such file or directory” for datadir, log, or socket |
Path or mount | Configuration spelling, mount state, parent directories | Mount the intended volume or correct the path; never initialize over existing data |
| Journal reports an AVC denial while Unix checks pass | SELinux policy/context | ausearch, audit log, ls -Z, port label |
Apply the distribution-supported file or port label; keep enforcing mode |
Do not apply a fix from a different row merely because it is familiar. For example, changing ownership cannot release a TCP port, and changing a port cannot repair an unlabeled data directory.
Special case: moving /var/lib/mysql
A data-directory move combines configuration, filesystem, ownership, and SELinux changes. On SELinux-enabled RHEL-family systems, Red Hat documents startup failures after moving the directory from /var/lib/mysql without assigning the new location the expected context.
- Stop the service and preserve the original directory until the new copy has been verified:
sudo systemctl stop mysqld. - Confirm the new filesystem is mounted at boot and that the copied files are complete. Compare ownership and representative file names before changing configuration.
- Set
datadirconsistently in the active MySQL configuration and in any package-specific override. Check for a second configuration file that still points to the old path. - Assign the persistent
mysqld_db_tfile context to the new tree withsemanage fcontext, then runrestorecon -Rv. - Confirm that the service account can traverse every parent directory and write where MySQL needs to create logs, temporary files, or a PID file.
- Start once, capture the journal and error log, and keep the original data directory untouched until a successful local connection and application test have completed.
If the copied directory is empty or lacks the expected system tables, stop and investigate the copy or mount. Starting an empty directory can create a new instance that appears healthy while the real databases remain elsewhere.
Restart once, then verify more than “active (running)”
After making the targeted correction, restart the installed unit and immediately collect before-and-after evidence:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →sudo systemctl restart mysqld
sudo systemctl status mysqld --no-pager -l
sudo journalctl -u mysqld -n 100 --no-pager
sudo tail -n 100 /path/to/mysql-error.log
sudo ss -ltnp | grep ':3306'
sudo mysqladmin --protocol=socket --socket=/path/to/mysql.sock ping
Use the configured port and socket in the checks. A successful systemctl state proves only that the process remained running long enough for systemd’s check; the local client test confirms that the server accepts connections through the intended endpoint. If socket authentication is configured differently, run an equivalent authenticated local client command rather than weakening authentication just for the test.
For a TCP-only configuration, test the configured address and port with the client instead of assuming the default socket. Confirm that the error log has no new fatal entries and that the listener belongs to the expected process. Record the final unit status, journal excerpt, effective datadir, port, socket, and SELinux context so a future change can be compared with a known-good state.
When the service still fails
- The same permission error returns: inspect a deeper parent directory, the log/PID path, and a fresh AVC timestamp. Ownership on the final data directory alone is not sufficient.
- The port is free but bind still fails: check whether the configured address exists on the host and whether SELinux labels the port as
mysqld_port_t. - The journal is empty: verify that you are reading the correct unit name and inspect
systemctl catfor an alternate launcher or wrapper. Then locate the error log from the active configuration. - Startup reaches crash recovery and exits: preserve the error log and database files. Do not remove InnoDB files or initialize the directory without a backup and a recovery plan.
- Two package families are installed: identify which unit owns the data directory and port. Disable only the unintended service after confirming that it is not the production instance.
If you cannot establish which process owns the data, port, or socket, stop making changes and obtain an administrator who can take a filesystem-level backup and review the logs. A cautious diagnosis is safer than repeated starts against an uncertain data directory.
Quick Recap
A compact repair checklist
- Identify the actual MySQL-compatible unit and package.
- Capture
systemctl status,journalctl -u, and the relevantjournalctl -xedetails. - Read the newest lines of the configured MySQL error log.
- Confirm
datadir, log, PID, socket, and port values from the active configuration. - Check mounts, paths, parent traversal, service-account ownership, and restrictive permissions.
- Check for SELinux AVC denials; label custom paths and ports through persistent policy rules.
- Check the configured TCP port, Unix socket, and running processes for conflicts.
- Make one narrow correction, restart once, and repeat status, journal, error-log, listener, and local-client checks.
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.




