Loading...

We've detected that your browser language is Chinese. Would you like to visit our Chinese website? [ Dismiss ]
By: Dylan

Cannot start MySQL Server?

When you try to start MySQL on Linux, you may encounter an error message like:

  • myserver systemd[1]: mysql.service: Failed to start MySQL Community Server
  • mysql.service: mysql.service: Failed with result ‘exit-code’

Failed to Start MySQL Community Server

Don’t worry, in this guide, we will explain the common causes of “Failed to start MySQL Community Server” and provide step-by-step solutions to help you diagnose and restore your MySQL server quickly.

Why can’t Start MySQL Community Server?

The common “Failed to start MySQL Community Server” errors are as follows:

  1. missing –secure-file-priv directory (most common cause)
  2. permission issue
  3. Configuration error in my.cnf
  4. port conflicts
  5. Corrupted InnoDB Log Files
  6. Insufficient Disk Space
  7. AppArmor or SELinux Restrictions

Check MySQL Service Status and Error Logs

Before changing any configuration files or reinstalling MySQL, the first step is to identify why the MySQL service failed to start. The error message shown by systemd is usually only a general indication that the startup process failed. The detailed cause is typically recorded in the MySQL error log.

1. Check the Error Log

On Ubuntu and Debian-based systems, the default error log is usually located at:

text
/var/log/mysql/error.log

You can view the latest errors with:

bash
sudo tail -50 /var/log/mysql/error.log

For real-time monitoring while restarting MySQL:

bash
sudo tail -f /var/log/mysql/error.log

You can also use systemd logs:

bash
sudo journalctl -xeu mysql.service

2. Check MySQL Service Status

Start by checking the current status of the MySQL service:

bash
sudo systemctl status mysql

You may see an output similar to:

  • mysql.service – MySQL Community Server
  • Loaded: loaded (/lib/systemd/system/mysql.service; enabled)
  • Active: failed (Result: exit-code)

How to Fix “Failed to Start MySQL Community Server” in Ubuntu/Linux

After checking the MySQL logs, you should have a more specific error message that points to the actual cause. Follow the solutions below and solve the problem.

Protect MySQL with Automated Backup Solution

Errors happen from time to time; to ensure business continuity, it is necessary to back up MySQL with Info2soft’s i2Backup. It allows you to back up all MySQL data from one console. Supports immutable backups, ransomware protection, and more. Learn More>>

FREE Trial for 60-Day

Method 1. Create missing –secure-file-priv Directory

One common reason for MySQL startup failure is that a directory specified in the MySQL configuration file does not exist.

If you see these in your error log:

text
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
[ERROR] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files[reference:11]ls -la /vmfs/volumes
vmkfstools -i source.vmdk -d thin dest.vmdk

then MySQL is configured to use /var/lib/mysql-files as the secure file import/export directory, but that directory doesn’t exist on your system.

Here is how to fix it.

Step 1. Identify the MySQL user-Check:

Check /etc/mysql/my.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf for the user directive. On Ubuntu/Debian systems, this is typically mysql.

Step 2. Create the missing directory

bash
sudo mkdir /var/lib/mysql-files

Step 3. Set the correct ownership

bash
sudo chown -R mysql:mysql /var/lib/mysql-files/

Step 4. Set appropriate permissions (optional but recommended)..

bash
sudo chmod 700 /var/lib/mysql-files/

Step 5. Restart MySQL:

bash
sudo systemctl start mysql

Once the directory exists with the correct ownership, MySQL will be able to access it and start successfully.

Method 2. Fix Incorrect MySQL Directory Permissions

Incorrect ownership or permissions on MySQL files are another common cause of startup failures.

MySQL runs under the mysql system user. If database files, log directories, or configuration-related folders are owned by another user (such as root), MySQL may not have permission to access required files.

The error log might show Permission denied messages related to /var/lib/mysql or /var/log/mysql.

Here are how to fix it.

• Check Current Permissions

bash
ls -ld /var/lib/mysql

The output should show mysql:mysql as the owner and group.

• Fix Ownership

If the ownership is incorrect, fix it with:

bash
sudo chown -R mysql:mysql /var/lib/mysql

• Fix Permissions

Set appropriate directory permissions:

bash
sudo chmod 750 /var/lib/mysql

Also check the log directory:

bash
sudo chown -R mysql:adm /var/log/mysql
sudo chmod 750 /var/log/mysql

After fixing permissions, try starting MySQL again.

Method 3. Fix Invalid MySQL Configuration Settings

A misconfigured my.cnf file is another common cause of prevent MySQL Community Server from starting.

MySQL’s main configuration files are typically located at:

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

Typical configuration mistakes include:

  • Syntax errors – Missing semicolons, incorrect section headers
  • Invalid parameter values – Setting innodb_buffer_pool_size to a value that exceeds available RAM
  • Referencing non-existent paths – Pointing to directories that don’t exist

Here are how to fix:

• Validate Your Configuration:

You can check for configuration errors with:

bash
mysql --verbose –-help

Or more specifically:

bash
mysqld --verbose –help

If there’s a syntax error, MySQL will typically print it when you try to start the service.

• Fix Configuration Errors

1. Open the configuration file:

bash
sudo nano /etc/mysql/my.cnf

2. Look for any obvious error, like incorrect paths, misspelled directives, or values that seem out of range.

3. Save the file and exit.

4. Attempt to restart:

bash
sudo systemctl restart mysql

If you’re unsure about a specific setting, comment it out temporarily (add # at the start of the line) and try starting MySQL without it.

Method 4. Free or change MySQL’s port

• Option 1: Free the Port

Identify the process using port 3306 and stop it if it’s safe to do so.

• Option 2. Change MySQL’s port

Edit my.cnf and add or modify:

text
[mysqld]
port = 3307

Then restart MySQL.

Method 5. Recover from InnoDB Startup Problems

If the MySQL error log contains messages related to InnoDB, such as:

  • “InnoDB: Unable to start”,
  • “InnoDB: Database page corruption”,
  • “InnoDB: Your database may be corrupt”
  • “InnoDB: Error: log file ./ib_logfile0 is of different size”

The InnoDB redo logs become corrupted due to an improper shutdown or system crash. And the MySQL community server may fail to start.

How to fix it:

Step 1. Stop MySQL (if it is partially running):

bash
sudo systemctl stop mysql

Step 2. Back up the existing log files:

bash
sudo mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak
sudo mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bak

Step 3. Start MySQL:

bash
sudo systemctl start mysql

MySQL will automatically recreate the log files with the correct size and format

Warning: Only remove InnoDB log files if you’re certain the data files themselves are intact. If the data files are also corrupted, you’ll need to restore from a backup or use InnoDB recovery tools.

Method 6. Free Up Disk Space

MySQL needs disk space to write temporary files, logs, and perform various operations. If your disk is full, MySQL won’t start.

• Check Disk Space

bash
df -h

Look for partitions that are at 100% usage, particularly the partition containing /var/lib/mysql.

Steps to Free Up Space:

  • Remove old log files: sudo rm -rf /var/log/mysql/*.log (but keep the most recent)
  • Clear package cache: sudo apt-get clean
  • Remove unused packages: sudo apt-get autoremove
  • Delete old backup files if you have any

After freeing space, attempt to start MySQL again.

Method 7. Solve AppArmor or SELinux Restrictions

On Ubuntu systems, AppArmor can silently block MySQL from accessing certain files or directories. On Red Hat-based systems, SELinux can cause similar issues.

• Check for AppArmor Issues

Look for messages like this in journalctl:

bash
apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld"[reference:28]

• Check AppArmor Status

bash
sudo aa-status

Look for the MySQL profile and whether it’s in enforce or complain mode.

How to fix:

Option 1. Temporarily disable AppArmor for MySQL (for testing only):

bash
sudo aa-disable /usr/sbin/mysqld

Option 2. Reload AppArmor profiles after making changes:

bash
sudo systemctl restart apparmor

Option 3. For SELinux systems, set the correct security context:

bash
sudo semanage fcontext -a -t mysqld_db_t "/var/lib/mysql-files(/.*)?"
sudo restorecon -Rv /var/lib/mysql-files
Note: Disabling security restrictions should be a temporary measure. The proper fix is to configure the security policy to allow MySQL’s legitimate operations.

How to Prevent “Failed to Start MySQL Community Server” issue

Hope the above solution can help you. To avoid the problem happening again, try the following best practices can help reduce the risk of MySQL service failures.

  1. Regular backups – Schedule automated backups of /var/lib/mysql and your databases.
  2. Monitor disk space – Set up alerts for low disk space.
  3. Use configuration management – Tools like Ansible or Puppet can prevent manual configuration errors.
  4. Keep MySQL updated – Many bugs, including the secure-file-priv directory issue, are fixed in newer versions.
  5. Test configuration changes – Always validate my.cnf changes in a staging environment first.
  6. Document your setup – Keep notes on your MySQL configuration for faster troubleshooting.

Protect MySQL Database with Automated Backup Solution

Troubleshooting errors like “Failed to Start MySQL Community Server” can help restore database availability, but preventing data loss requires a reliable backup and recovery strategy.

Unexpected MySQL failures can happen due to various reasons, including configuration mistakes, storage issues, hardware failures, accidental deletion, or database corruption. Without a recent and reliable backup, recovering a failed MySQL server can become a time-consuming and risky process.

i2Backup is an enterprise backup solution designed to protect critical databases, including MySQL, Oracle, SQL Server, and other business applications. It helps organizations automate database backup, simplify recovery operations, and maintain business continuity.

i2Backup Dashboard

i2Backup’s main advantages:

1. Automated MySQL Backup and Recovery

i2Backup enables administrators to create scheduled backup policies and retention policies to automate MySQL data protection tasks.

2. Protect MySQL Data Against Unexpected Failures

When a MySQL service cannot start due to corruption, system failures, or configuration problems, having verified backups allows administrators to quickly restore databases to a previous healthy state.

i2Backup supports database backup and recovery with features such as: full and incremental backups, table-level recovery, and multiple backup storage targets. These capabilities help organizations reduce downtime and improve database resilience.

3. Centralized Management for Enterprise Environments

i2Backup provides centralized management through a graphical interface, allowing administrators to easily monitor backup jobs, view backup reports, manage backup policies, and more. This simplifies database protection in large-scale IT environments.

4. Support Multiple Storage Options and Disaster Recovery Scenarios

i2Backup supports backing up MySQL to tape, local disk, ZFS storage, object storage, and more, helping organizations build flexible backup and disaster recovery strategies.

By combining regular MySQL backups with proper recovery planning, organizations can minimize the impact of database failures and maintain continuous business operations.

Click the button below to request a 60-day free trial.

FREE Trial for 60-Day

Conclusion

The “Failed to Start MySQL Community Server” error is a common MySQL startup issue, but the underlying cause can range from missing directories or incorrect permissions to configuration errors, disk space issues, or database corruption.

The most effective way to resolve the issue is to start with a systematic troubleshooting process: check the MySQL service status, review error logs, identify the specific cause of the failure, and apply the appropriate fix rather than making unnecessary changes.

However, restoring a failed MySQL service is only part of maintaining database availability. Unexpected failures, data corruption, and system issues can still put critical databases at risk. A reliable backup and recovery strategy helps ensure that your MySQL databases can be restored quickly when problems occur. Using Info2soft‘s i2Backup, organizations can minimize downtime, protect valuable data, and maintain more resilient MySQL environments.

Dylan has 8+ years of experience in enterprise data management, server optimization, and disaster recovery. He specializes in translating complex technical concepts into actionable guides for IT administrators and DevOps teams, with a focus on data security, cloud migration, and business continuity.

More Related Articles

Table of Contents:
Stay Updated on Latest Tips
Subscribe to our newsletter for the latest insights, news, exclusive content. You can unsubscribe at any time.
Subscribe
Ready to Enhance Business Data Security?
Start a 60-day free trial or view demo to see how Info2soft protects enterprise data.
Please fill out the form and submit it, our customer service representative will contact you soon.
By submitting this form, I confirm that I have read and agree to the Privacy Notice.
{{ isSubmitting ? 'Submitting...' : 'Submit' }}