If MySQL encounters critical issues, such as an InnoDB crash, it may fail to start or become unstable. Follow these steps to recover MySQL and restore your databases in a Plesk environment.
Start MySQL in Recovery Mode
To force MySQL to start in recovery mode:
1. Edit the MySQL configuration file (`my.cnf`):
vim /etc/my.cnf
2. Add the following lines to enable recovery mode:
[mysqld] innodb_force_recovery=1
– The `innodb_force_recovery` value can be set from `1` to `7`. Start with `1` and increase if needed.
– Higher values (`4-6`) make the database read-only and may cause data loss.
3. Restart MySQL:
systemctl restart mysqld
2. Backup MySQL Databases
Once MySQL starts in recovery mode, immediately back up your databases.
1. List available databases:
mysqlshow
2. Dump each database** (replace `[db_name]` with the actual database name):
mysqldump -u root -p [db_name] > [db_name].sql
3. Backup the entire MySQL data directory:
tar -czvf /var/lib/mysql.tar.gz /var/lib/mysql
3. Remove MariaDB and Corrupted Data
1. Find installed MariaDB packages:
rpm -qa | grep -i mariadb
2.Remove MariaDB without affecting dependencies:
rpm -e --nodeps mariadb-server
3. Delete the MySQL data directory (if necessary):
rm -rf /var/lib/mysql
4. Reinstall MariaDB
1. Install MariaDB again:
dnf install mariadb-server
2. Start and enable MariaDB service:
systemctl enable --now mysqld
5. Restore Databases from Backup
1. Create databases (before importing backups):
mysql -u root -p CREATE DATABASE [db_name];
2. Restore each database:
mysql -u root -p [db_name] < [db_name].sql
3. Restore the MySQL system database (last):
mysql -u root -p mysql < mysql.sql
6. Final Cleanup and Restart
1. Remove `innodb_force_recovery` from `my.cnf`:
vim /etc/my.cnf
– Delete or comment out the `innodb_force_recovery` line.
2. Restart MySQL normally:
systemctl restart mysqld
Important Notes
✅ Always backup databases before making changes.
✅ Higher values of `innodb_force_recovery` can cause data loss.
✅ Removing MariaDB is a last resort—try repairing tables first.
✅ If the MySQL system database (`mysql.sql`) is corrupt, reinstallation may be required.
Following these steps should help recover MySQL in a Plesk environment when it’s in a problematic state. 🚀