Recover MySQL DB
Recover MySQL DB
I had a Google Cloud VM Instance fail and needed to recover the MySQL DB for which I only had an old backup. I detached the HDD from the broken instance and attached it to a new one and mounted it
Mount old Drive
# mount old drive
sudo -s
mkdir /mnt/olddrive
mount /dev/sdb1 /mnt/olddrive
Copy MySQL files
I then copied all the files from the old drive to the new one. Stop MySQL/MariaDB
cp -rv /mnt/olddrive/var/lib/mysql/data/database /var/lib/mysql/data/database
cp -rv /mnt/olddrive/var/lib/mysql/data/ib* /var/lib/mysql/data/
This also works if the new instance is running MariaDB instaed of MySQL
Set permissions
In my instance I also had to change permissions as the new instance used slightly different ones. Your permissions might be different.
chown -R mysql:mysql /var/lib/mysql/data/database
chown mysql:mysql /var/lib/mysql/data/ib*
chmod 660 /var/lib/mysql/data/database/*
chmod 700 /var/lib/mysql/data/database
chmod 700 /var/lib/mysql/data/ib*
Start MySQL/MariaDB - the database should be back.