Skip to content
WJunction - Webmaster Forum

mysql auto repair table upon crash

Status
Not open for further replies.
many times, i see my forum down due to corrupted table, mostly the session table.

is there anyway to automatically repair tables when they are detected/marked as corrupted?
 

8 comments

problem happened in both ipb and vb and both in session table. remember session table is memory and on vps we always have memory issues.
 
Sounds to me like your looking for a pump to remove water from a leak. Would the obvious thing not be to fix the leak and cause of the problem?

Remove some memory heavy functions or upgrade your server. Relying on a script to repair corrupted tables is a bad idea.
 
I would suggest putting the sessions back to MyIsam from memory. That works well if you have a lot of memory and a large number online.

But it will crash a lot on a vps with minimal memory. That is why IPB made it using MyIsam in the first place.
 
an loop
CHECK TABLE foreach table msg !=ok repair, optimize

or
PHP:
$alltables = mysql_query("SHOW TABLES");
while ($table = mysql_fetch_assoc($alltables))
{
   foreach ($table as $db => $tablename)
   {
       mysql_query("OPTIMIZE TABLE '".$tablename."'")
           or die(mysql_error());
           echo $tablename." Opmizide<br />";
   }
      foreach ($table as $db => $tablename)
   {
       mysql_query("REPAIR TABLE '".$tablename."'")
           or die(mysql_error());
           echo $tablename." Repaired<br />";
   }
}
 
Last edited:
Status
Not open for further replies.

About the author

T
Banned · Joined
PHP, Girls
423
Messages
2
Reactions
18
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom