George Karani

Software Developer

Computer Engineer

0

No products in the cart.

George Karani

Software Developer

Computer Engineer

Blog Post

Recovering a Corrupted Plesk Server Database (MariaDB/MySQL)

June 12, 2025 Tech
Recovering a Corrupted Plesk Server Database (MariaDB/MySQL)

Encountering a database corruption on your Plesk-managed MariaDB or MySQL server can be daunting, but here’s a clear, step-by-step approach to safely recovering your databases and restoring your websites.

Step 1: Identifying the Issue

The common symptom is when the MariaDB/MySQL server refuses to start, reporting errors related to the InnoDB engine (such as corrupted ibdata1 files). Typical messages include:

[ERROR] InnoDB: Corrupted page
[ERROR] Can't open the mysql.plugin table

Step 2: Exporting All Databases (When Possible)

If your database server can start in a recovery mode (innodb_force_recovery), export all your databases immediately:

mkdir -p /root/mysql_backups

Use the following command to export all databases at once:

mysql -u root -p -e 'SHOW DATABASES;' | grep -Ev "(Database|information_schema|performance_schema|sys)" | while read dbname; do mysqldump -u root -p "$dbname" > "/root/mysql_backups/$dbname.sql"; done

Step 3: Preparing a Fresh MariaDB/MySQL Environment

Stop the service:

systemctl stop mariadb

Rename the old corrupted database directory:

mv /var/lib/mysql /var/lib/mysql_old
mkdir /var/lib/mysql
chown mysql:mysql /var/lib/mysql
chmod 750 /var/lib/mysql

Initialize a new database environment:

mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Restart MariaDB/MySQL:

systemctl start mariadb

Step 4: Import All Databases at Once

Create and import all databases using the following command:

for file in /root/mysql_backups/*.sql; do
  db=$(basename "$file" .sql)
  mysql -u root -p -e "CREATE DATABASE \`$db\`;"
  mysql -u root -p "$db" < "$file"
done

Step 5: Restore Database Users and Permissions

Recreate the database users and permissions for each database:

CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON example_database.* TO 'example_user'@'localhost';
FLUSH PRIVILEGES;

Repeat these steps for each database user you previously had.

Step 6: Verify Your Setup

Check databases are present:

mysql -u root -p -e "SHOW DATABASES;"

Ensure your websites or apps (e.g., WordPress, Laravel) have correct database credentials in their respective configuration files (like wp-config.php for WordPress):

define('DB_NAME', 'your_database_name');
define('DB_USER', 'example_user');
define('DB_PASSWORD', 'strong_password_here');
define('DB_HOST', 'localhost');

Step 7: Final Check & Repair (Plesk)

Run a repair on Plesk installation to fix any remaining issues:

plesk repair all -y

Best Practices After Recovery:

  • Schedule regular database backups.
  • Monitor database performance and disk space.
  • Consider periodic database health checks.

By carefully following these steps, you can efficiently restore your corrupted Plesk-managed MariaDB/MySQL databases and return your websites to operational status.

Write a comment