Diagnosing and Resolving MySQL/MariaDB Startup Issues on Ubuntu
When MySQL refuses to start on an Ubuntu server, it can bring applications to a standstill. Whether we are managing a production database or a development environment, knowing how to systematically diagnose and fix these failures is essential. This guide covers the most common reasons MySQL (or MariaDB) fails to start and walks through proven solutions.
1. Checking MySQL/MariaDB Service Status
Before investigating specific problems, we should verify the current state of the database service. This tells us whether the process is running, stopped, or stuck in a failed state.
sudo systemctl status mysql
For MariaDB installations:
sudo systemctl status mariadb
2. Analyzing Log Files
Log files are the single most valuable resource when troubleshooting startup failures. MySQL and MariaDB write detailed error information that points directly to the root cause.
- Error Log: Typically located at
/var/log/mysql/error.logor for MariaDB at/var/log/mysql/mariadb/error.log.
sudo less /var/log/mysql/error.log
For MariaDB:
sudo less /var/log/mariadb/error.log
We recommend searching for lines containing ERROR or FATAL to quickly identify the problem.
3. Common Startup Failures and Fixes
3.1 Insufficient Disk Space
A full disk prevents MySQL from writing temporary files or logs, which stops the service cold. We can verify available space with:
df -h
Focus on the partition that holds /var/lib/mysql. If space is critically low, remove old logs, temporary files, or unused packages to free room.
3.2 Incorrect File Permissions
MySQL requires specific ownership on its data directory. If permissions were accidentally changed, the service cannot read or write its files.
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod 755 /var/lib/mysql
3.3 Corrupted InnoDB Log Files
InnoDB log corruption can prevent MySQL from completing its recovery sequence during startup. If the error log references InnoDB redo log issues, we can try removing the log files and letting MySQL recreate them:
sudo systemctl stop mysql
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
sudo systemctl start mysql
Important: Always back up these files before removing them.
3.4 Configuration Errors in my.cnf
A typo or invalid directive in the MySQL configuration file will prevent startup. We should review the config for syntax issues:
sudo nano /etc/mysql/my.cnf
Common mistakes include invalid innodb_buffer_pool_size values, incorrect socket paths, or referencing plugins that are not installed. After making corrections, restart the service:
sudo systemctl restart mysql
3.5 Port Conflicts
If another process is already using port 3306, MySQL will fail to bind. We can check for conflicts with:
sudo lsof -i :3306
Either stop the conflicting process or change the MySQL port in the configuration.
3.6 AppArmor or SELinux Restrictions
On Ubuntu, AppArmor profiles can block MySQL from accessing required paths. Check whether AppArmor is enforcing restrictions:
sudo aa-status
If MySQL appears in the enforced list and startup logs mention permission denials, we may need to adjust the AppArmor profile or switch it to complain mode temporarily for testing.
4. Recovery Steps
If none of the above resolves the issue, we can attempt a more thorough recovery:
- Check for pending upgrades: Run
sudo apt update && sudo apt upgradeto ensure MySQL packages are fully up to date. - Reinstall the package:
sudo apt install --reinstall mysql-servercan fix missing or corrupted binaries without touching data files. - Run mysqlcheck: Once MySQL starts, use
mysqlcheck --all-databases --repairto repair any damaged tables.
5. Preventive Measures
- Monitor disk usage with automated alerts to catch low-space conditions early.
- Automate backups of both the data directory and configuration files.
- Test configuration changes in a staging environment before applying them to production.
- Keep software updated to benefit from bug fixes and security patches.
By following a methodical approach, starting with service status, moving through logs, and systematically checking each common failure point, we can resolve most MySQL startup issues quickly and minimize downtime.
Need help with this?
Our team handles this kind of work daily. Let us take care of your infrastructure.
Related Articles
From Code to Production: A Guide to Automating Laravel Deployments with GitHub Actions
Learn how to build a fully automated CI/CD pipeline for Laravel using GitHub Actions, covering SSH key setup, workflow configuration, testing, and deployment to production servers.
LaravelStep-by-Step Guide to Deploying a Laravel App on AWS with Laravel Forge
A complete walkthrough of deploying a Laravel application on AWS EC2 using Laravel Forge, covering instance setup, Forge configuration, environment variables, SSL, and production best practices.
LaravelMastering Laravel Workers: A Step-by-Step Guide to Setting Up a Laravel Worker Server on Ubuntu
A comprehensive guide to setting up Laravel queue workers on Ubuntu, covering Redis configuration, job creation, Supervisor process management, Horizon monitoring, scaling, and troubleshooting.