Things to note:
- You will need the same version of the database on the machine you want to recover the database
- Don’t use a production database/server for recovery
The process is very simple and straight forward. You will need the following files from the raw files backup you have.
On your test server, 1st shutdown the database server.
systemctl stop mariadb OR systemctl stop mysqld
Next we will make a copy of our current database directory, so later we can restore it once we are done.
cp -r /var/lib/mysql /var/lib/mysql_org
Once completed, copy over the raw files mentioned above.
cp /path/to/database /var/lib/mysql cp /path/to/ib_logfile0 /var/lib/mysql cp /path/to/ib_logfile1 /var/lib/mysql cp /path/to/ibdata1 /var/lib/mysql cp /path/to/ib_buffer_pool /var/lib/mysql
Changing ownership of the copied files is important and not to be missed.
chown -R mysql:mysql /var/lib/mysql/database chown -R mysql:mysql /var/lib/mysql/ib*
You can now start the database server.
systemctl start mariadb OR systemctl start mysqld
Backup your database using
mysqldump -u root -p DATABASE > /path/to/backups/db.sql
Once you have successfully created a backup of the database. You can restore your old databases directory.
systemctl stop mariadb OR systemctl stop mysqld mv /var/lib/mysql /var/lib/mysql_rm mv /var/lib/mysql_org /var/lib/mysql systemctl start mariadb OR systemctl start mysqld