Skip to main content
All CollectionsVPSVPS Management
How to Recover MySQL Databases From MySQL Data Files in VPS
How to Recover MySQL Databases From MySQL Data Files in VPS

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

Updated over 3 months ago

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, follow these steps:

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

That's it. Now, your databases have been fully recovered!

Did this answer your question?