Common Issues

MySQL/MariaDB Won't Start

Diagnose and fix MySQL or MariaDB that fails to start, common causes and step-by-step solutions

MySQL or MariaDB failing to start is usually caused by a handful of well-known issues: corrupt InnoDB logs, full disk, wrong permissions, or a port conflict. This guide covers the most common causes.


Step 1: Check the error logs

Always start here:

# MySQL
sudo journalctl -u mysql -n 100 --no-pager

# MariaDB
sudo journalctl -u mariadb -n 100 --no-pager

# Or check the error log file directly
sudo tail -50 /var/log/mysql/error.log

The error message in the log tells you exactly what's wrong in most cases.


Cause 1: Disk full

[ERROR] InnoDB: Write to file ./ibdata1 failed
[ERROR] Error writing file '/var/lib/mysql/binlog.000001'

Check disk usage:

df -h
du -sh /var/lib/mysql/

Free up space:

# Remove old binary logs (safe if no replicas depend on them)
sudo mysql -e "PURGE BINARY LOGS BEFORE NOW();"

# Or truncate logs
sudo journalctl --vacuum-size=200M

# Check for large temp files
find /tmp -size +100M 2>/dev/null

After freeing space, start the service:

sudo systemctl start mysql

Cause 2: Corrupt InnoDB redo logs

[ERROR] InnoDB: Log file ./ib_logfile0 is of different size
[ERROR] InnoDB: Plugin initialization aborted with error

Remove and regenerate the InnoDB log files (safe, they are regenerated automatically):

sudo systemctl stop mysql
sudo mv /var/lib/mysql/ib_logfile0 /tmp/ib_logfile0.bak
sudo mv /var/lib/mysql/ib_logfile1 /tmp/ib_logfile1.bak
sudo systemctl start mysql

If MySQL starts successfully, delete the backups:

rm /tmp/ib_logfile*.bak

Cause 3: Port already in use

[ERROR] Can't start server: Bind on TCP/IP port. Got error: 98: Address already in use

Find what's using port 3306:

sudo ss -tlnp | grep 3306

If another process is using it:

# Find and kill
sudo fuser -k 3306/tcp
sudo systemctl start mysql

If MySQL is already running as a zombie process:

sudo pkill mysqld
sudo systemctl start mysql

Cause 4: Wrong file permissions

[ERROR] Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
[ERROR] mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid'

Fix ownership:

sudo chown -R mysql:mysql /var/lib/mysql
sudo chown -R mysql:mysql /var/run/mysqld
sudo chmod 755 /var/run/mysqld
sudo systemctl start mysql

If /var/run/mysqld doesn't exist:

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo chmod 755 /var/run/mysqld
sudo systemctl start mysql

Cause 5: Corrupted system tables

[ERROR] Fatal error: Can't open and lock privilege tables: Incorrect file format 'user'

Run the repair tool:

sudo systemctl stop mysql

# MySQL
sudo mysqld --tc-heuristic-recover=ROLLBACK

# MariaDB
sudo mysqld --tc-heuristic-recover=ROLLBACK

sudo systemctl start mysql

If that fails, repair with --skip-grant-tables:

sudo mysqld_safe --skip-grant-tables &
sleep 5
mysql -u root -e "REPAIR TABLE mysql.user;"
mysql -u root -e "FLUSH PRIVILEGES;"
sudo killall mysqld
sudo systemctl start mysql

Cause 6: Configuration syntax error

[ERROR] unknown variable 'innodb_buffer_pool_size1=128M'

Test the config file for syntax errors:

# MySQL
mysqld --validate-config

# MariaDB
mysqld --help --verbose 2>&1 | head -20

Then check /etc/mysql/mysql.conf.d/mysqld.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf for typos.


Cause 7: AppArmor blocking MySQL

[ERROR] Could not open file '/var/lib/mysql-files/' for error logging: Permission denied

Check AppArmor:

sudo aa-status | grep mysql
sudo journalctl -k | grep DENIED | grep mysql

If AppArmor is blocking it:

# Temporarily disable MySQL AppArmor profile
sudo aa-disable /etc/apparmor.d/usr.sbin.mysqld
sudo systemctl start mysql

For a proper fix, update the AppArmor profile instead of disabling it.


Emergency: force InnoDB recovery

If none of the above works and you suspect severe InnoDB corruption, add to /etc/mysql/mysql.conf.d/mysqld.cnf:

[mysqld]
innodb_force_recovery = 1

Try starting with levels 1 through 6 until it starts. Once started, immediately dump all databases:

mysqldump --all-databases > /root/full-backup-$(date +%F).sql

Then remove the recovery option and restart cleanly.

innodb_force_recovery mode is read-only. Do not use it for normal operation. Increase the level only if the previous level failed to start the service.


Quick reference

Error keywordLikely causeFix
No space leftDisk fullFree disk space
ib_logfileCorrupt InnoDB logsRemove ib_logfile*
Address already in usePort conflictKill other process
Permission deniedWrong ownershipchown -R mysql:mysql
unknown variableConfig typoFix mysqld.cnf
Can't open privilege tablesMissing data dirReinitialize or restore

On this page