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-serverIt’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 stopStep 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/mysqlAfter 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/mysqlWhen all is good to go, start your MySQL server:
service mysql startStep 3 – Final checks and export
Check and repair all the database tables to ensure no data is corrupted:
mysqlcheck -rANOTE
-
Depending on the version of MySQL you are running, you should run MYSQLCHECK
Lastly, export the databases:
mysqldump --all-databases > all_databases.sqlYour MySQL databases are now recovered and exported to all_databases.sql.