PDA

View Full Version : How to Check, Recover & Repair MySQL Databases


UKBusinessLive
03 Jan 2009, 20:32
Looks Familiar??? No matter how much you manage your sever, at one stage in your dealings with MySQL Databases you will get errors, So what do you do ??

jtablesession::Store Failed
DB function failed with error number 145
Table './webkinzc_jo151/jos_session' is marked as crashed and should be repaired SQL=INSERT INTO `jos_session` ( `session_id`,`time`,`username`,`gid`,`guest`,`client_id` ) VALUES ( 'fd773853ae5aa0aca6aa7c22c79dcbbd','1230945305','','0','1','0' )

How to repair all MySQL Databases on a cPanel Server

There can be different reasons why one wants to repair a MySQL database. Database corruption maybe due to a lack of disk space or an unexpected server shutdown that caused the database to go bad. Queries that worked before suddenly stopped working and overall the database is not behaving anymore as expected. This post is not a full database troubleshooting guide, but rather give you a hand on doing a MySQL repair on all databases on a cPanel/WHM server (or any other server running MySQL).

The situation: Your server crashed hard and when it is back up the MySQL side of the house is not working anymore. You do your normal troubleshooting. If all other troubleshooting and verifications are done, you come to the conclusion that you will need to run a repair as the next step. A full database restore from a (hopefully existing) good database backup would be your last choice.

Repairing one MySQL database is fairly easy, but how do you do this for an entire server holding20, 30, 50 or over 100 databases? You will need SSH access as the root user to the server running MySQL. So, log in as the root user and then do the following to repair your MySQL databases:

Option #1

Check if you any need DB repair:
myisamchk --check /var/lib/mysql/*/*.MYI

Then try a 'safe-recover' as the first step:
myisamchk --safe-recover /var/lib/mysql/*/*.MYI

If the ‘safe-recover’ does not work, run a full recover:
myisamchk --recover /var/lib/mysql/*/*.MYI

Then use the 'force' flag to get things back to normal:
myisamchk --safe-recover --extend-check --force /var/lib/mysql/*/*.MYI

or:
myisamchk --recover --extend-check --force /var/lib/mysql/*/*.MYI



Option #2

Use the mysqlcheck tool to repair your databases.

mysqlcheck --all-databases -r #repair
mysqlcheck --all-databases -a #analyze
mysqlcheck --all-databases -o #optimize

Option #3

1) Through cPanel:

Log in to your cPanel and go to MySQL Databases. In the section Modify Databases, select a database from the drop-down box next to Repair DB: and then click the Repair DB button.

If the database engine used by your database supports repair (for example, MyISAM supports it), you will see a list of the repaired tables within the database.

If your database engine does not support repair (e.g. InnoDB database engine), you will get the following error message:

note : The storage engine for the table doesn't support repair

2) Through phpMyAdmin:

Open your phpMyAdmin tool and select the database whose tables you wish to repair.

A list with all the database's tables will appear. Tick the tables you wish to repair, or simply click [Check All] to select all tables.

Click the box [With selected:] and choose Repair table. This will execute the REPAIR TABLE SQL query on the selected tables and they will be repaired.

There you have it. By using one of these threee options you should be able to repair and recover your databases. Please be advised that you should backup critical databases before running any of the commands above. If something goes wrong you can revert back and try again.

In general the idea is to get people feeling confident enough to be able to work out a solution to a problem rather than worrying that they have a major serious issue.

Hope that helps :D

NAZIA
16 Jan 2009, 22:31
Thanks for sharing...
what does the Repair / Optimize Tables

OR
http://xyz.xyz /admincp/repair.php?do=list
Do in the admincp of the vbulletin?

VK3MTR
18 Jan 2009, 01:42
Thanks man, appreciate the advice. :)

harisafp
19 Jan 2009, 06:26
Good for solutions ...
Thanks !!

Jasem
04 Apr 2009, 04:10
great work, thank you!

ragtek
06 Apr 2009, 22:30
I think it would be better placed here=> http://www.vbulletin.org/forum/forumdisplay.php?f=188 it's no vb article..

also pls see this: http://www.vbulletin.org/forum/showthread.php?t=210032 but no feedback:(

Golzarion
26 Jul 2009, 16:32
Thanks .Nice article .

m2006
30 Jun 2011, 13:00
Thank you for advice

itilm
09 Sep 2011, 14:12
if forum not running & data not Restore so....???