There might be a situation when your VPS cannot be started. If you are trying to recover MySQL databases from VPS Recovery Mode or VPS backup files, here is what you should do.
Step 1 - Install and stop MySQL server
First things first, you need to connect to your VPS via SSH. When that is done, 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 possible.
After the MySQL server is installed, it's time to stop it in order to add to the data folders. The command for that:
service mysql stop
Step 2 - Copy data
Now, we need to copy old MySQL data to the new MySQL server data files location. For this, use:
cp -rf /mnt/var/lib/mysql/* /var/lib/mysql
After the command is completed, we need to ensure that the files are owned by the MySQL user. For that change files ownership, using:
chown -R mysql:mysql /var/lib/mysql
Everything is correct? Then start your MySQL server:
service mysql start
Step 3 - Final checks and export
We are almost there! To ensure that the data is not corrupted, we need to check and repair all the database tables. The command for that is:
Depending on the version of MySQL you are running, you should run MYSQLCHECK
And the last step - export databases:
mysqldump --all-databases > all_databases.sql
Congratulations, your databases are fully recovered!