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.logThe 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/nullAfter freeing space, start the service:
sudo systemctl start mysqlCause 2: Corrupt InnoDB redo logs
[ERROR] InnoDB: Log file ./ib_logfile0 is of different size
[ERROR] InnoDB: Plugin initialization aborted with errorRemove 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 mysqlIf MySQL starts successfully, delete the backups:
rm /tmp/ib_logfile*.bakCause 3: Port already in use
[ERROR] Can't start server: Bind on TCP/IP port. Got error: 98: Address already in useFind what's using port 3306:
sudo ss -tlnp | grep 3306If another process is using it:
# Find and kill
sudo fuser -k 3306/tcp
sudo systemctl start mysqlIf MySQL is already running as a zombie process:
sudo pkill mysqld
sudo systemctl start mysqlCause 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 mysqlIf /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 mysqlCause 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 mysqlIf 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 mysqlCause 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 -20Then 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 deniedCheck AppArmor:
sudo aa-status | grep mysql
sudo journalctl -k | grep DENIED | grep mysqlIf AppArmor is blocking it:
# Temporarily disable MySQL AppArmor profile
sudo aa-disable /etc/apparmor.d/usr.sbin.mysqld
sudo systemctl start mysqlFor 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 = 1Try starting with levels 1 through 6 until it starts. Once started, immediately dump all databases:
mysqldump --all-databases > /root/full-backup-$(date +%F).sqlThen 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 keyword | Likely cause | Fix |
|---|---|---|
No space left | Disk full | Free disk space |
ib_logfile | Corrupt InnoDB logs | Remove ib_logfile* |
Address already in use | Port conflict | Kill other process |
Permission denied | Wrong ownership | chown -R mysql:mysql |
unknown variable | Config typo | Fix mysqld.cnf |
Can't open privilege tables | Missing data dir | Reinitialize or restore |