Fixing mysql crash caused by InnoDB
The Problem
I ran a moodle application on ubuntu inside virtual machine (virtualbox). It has been working fine for a long time until one day, it decided to stop working in the middle of an exam participated by -+ 40 students. It shows that the database is somehow crashed.Diagnosis
I tried to open the mysql using mysql client, and i'm unable to.ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock'
/etc/init.d/mysql start
start: Job failed to start
First, because i ran the system in a vm, i thought it was either the disk space or memory, so i ran df command then found out it currently use only 5% of the total disk spaces. And then i ran htop and it only used <500MB from the total of 8GB allocated to the vm so i ruled out both possibility.
Ok, so i know there are something definitely wrong with the mysql server. So, just in case, i made a backup to the mysql data directory into my home dir (and you should do to, backup is very important afterall)
sudo cp -rp /var/lib/mysql ~/mysql/
I checked the mysql logs:
cat /var/log/mysql.log cat /var/log/mysql.err
cat /var/log/mysql.err
mysqld got signal 11 ; This could be because you hit a bug. It is also possible that this binary or one of the libraries it was linked against is corrupt, improperly built, or misconfigured. This error can also be caused by malfunctioning hardware. Attempting to collect some information that could help diagnose the problem. As this is a crash and something is definitely wrong, the information collection process might fail. ......
Solution
After scouring the web for solution, i came across a possibility that my innodb database is corrupted. So as a trial and error, i remove these 3 files:/var/lib/mysql/ibdata1 /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile1
Before continuing, stopped the mysql server again, then copy those 3 files from the backup i've made, then start the mysql server again. As expected, it failed to start.
After scouring the web again, i've found a solution to run mysql server in innodb force recovery mode. I open /etc/mysql/my.cnf using nano, then add these lines:
innodb_force_recovery = 2 innodb_purge_threads = 0
Taken from the link above:After the mysql server runs, i connect to the mysql using
2 (SRV_FORCE_NO_BACKGROUND)
Prevents the master thread and any purge threads from running. If a crash would occur during the purge operation, this recovery value prevents it.
mysql -u root -p
In this state, you won't be able to insert or update anything in the database. You can only read and drop things. So the idea here is to dump the corrupted table to a file somewhere, drop the table from database, and then import the dumped file back into database.
I run mysqlcheck to see which tables is corrupted:
mysqlcheck -u root -p --all-databases
and it says all my tables is OK.
in my case, i have to pipe the command to "more" command because i have a lot of tables.This confuse me as i don't know which table i should dump. So i dump my database into a file as a backup. Luckily, my database is not too big to dump.
mysqlcheck -u root -p --all-databases | more
mysqldump -u root -p [pass] [db name] > [db name].sql
If in your case you found out the corrupted table when you do mysqlcheck, you should only dump that corrupted table to avoid bloating the dump file. Especially when your database is big.
mysqldump -u root -p [pass] [db name] [table name] > [db name].[table name].sql
Then i drop the whole database, create a new database with same name, and import the dumped file back into that database.
Be careful, in your case, you might only need to drop the corrupted table, not the whole database.
And after the import proccess is finished. My moodle application can run normally.
Subscribe to:
Post Comments
(
Atom
)
El Cortez - Casino Restaurants | Mapyro
ReplyDelete› restaurants 안산 출장안마 군포 출장안마 › restaurants 광양 출장샵 El Cortez, El Cortez, located in 서귀포 출장마사지 El Cortez, features 392 slot machines, over 1500 table games, poker tables, an expansive roster of restaurants, a casino and 아산 출장마사지
Are you looking to elevate your travel with Asiana Airlines? Need help on How to cancel and refund at Asiana Airlines Flight? For assistance, contact Asiana Airlines at OTA+1 800 970 3794 (no wait).
ReplyDeleteHow to cancel and refund at Asiana Airlines Flight?