Thursday, July 14, 2016

Restoring Innodb Database On Ubuntu Linux from Power Failure


I received a ticket from a customer that we setup wordpress before, usually we did not do this but somehow we did.

I'm not sure why but they did copy the whole Ubuntu directory as a backup so I can get a copy of the /var/lib/mysql

This is how I did it.


Edit /etc/mysql/my.cnf to include below line;
[mysqld]
innodb_force_recovery = 1

I manage to start the mysql service and do mysqldump;
mysqldump -u user -p databasename > path/to/databasename.sql

Next, remove the changes on /etc/mysql/my.cnf, start the mysql service, drop and create the database and import the .sql file.
DROP DATABASE databasename;
CREATE DATABASE databasename;
mysql -u root -p databasename < path/to/databasename.sql

Now the database table is accessible. Login to mysql;
mysql -u user -p 
Select database and query the tables and confirm it return data.
USE databasename;
SELECT * FROM wp_users;

No comments:

Post a Comment