How to recover MySQL databases from MySQL data files in VPS at Hostinger

Recovering MySQL databases from MySQL data files /var/lib/mysql

Updated 1 week ago

To recover MySQL databases from MySQL data files on a Hostinger VPS, install and stop a MySQL server, copy the old data to /var/lib/mysql, fix the file ownership, then check, repair, and export the databases. Use this method when your VPS can’t start and you’re recovering from VPS Recovery Mode or VPS backup files.

Step 1 – Install and stop MySQL server

Connect to your VPS via SSH and install MySQL server by running this command:

yum install mysql-server

It’s recommended to use the same version of MySQL. However, using a newer version is also possible.

After the MySQL server is installed, it’s time to stop it to add to the data folders:

service mysql stop

Step 2 – Copy the data

Use the following command to copy your old MySQL data to the new MySQL server data files’ location:

cp -rf /mnt/var/lib/mysql/* /var/lib/mysql

After the command is executed, verify that the files are owned by the MySQL user. by changing the files’ ownership:

chown -R mysql:mysql /var/lib/mysql

When all is good to go, start your MySQL server:

service mysql start

Step 3 – Final checks and export

Check and repair all the database tables to ensure no data is corrupted:

mysqlcheck -rA

NOTE

  • Depending on the version of MySQL you are running, you should run MYSQLCHECK

Lastly, export the databases:

mysqldump --all-databases > all_databases.sql
See How to back up or restore a Hostinger VPS for other details about restoring a VPS from a backup.

Your MySQL databases are now recovered and exported to all_databases.sql.