Repair all mysql databases-tables with PHP

phpMyAdmin is a great tool but there is no option to repair all databases at once yet. Imagine you have no shell-access and need to repair all your 100 databases. It would take long time. This small PHP-Script lets you list, analyze and repair all your databases belong to same user at once.

If you already have shell access you can do it with mysqlcheck:

mysqlcheck -u root -p --auto-repair --check --optimize --all-databases

Repair with PHP:

List Analyze Repair
<?php /** * powered by * free for private use * please support us with donations */ $db_host = $_POST['db_host']; $db_user = $_POST['db_user']; $db_password = $_POST['db_password']; $do_analyze = $_POST['do_analyze']; $do_repair = $_POST['do_repair']; $db_ignore = ($_POST['db_ignore']) ? $_POST['db_ignore'] : "nodbignore" ; if(!$db_host || !$db_user){ die(); } mysql_connect("$db_host","$db_user","$db_password") or die("Error: No BD Connection"); $rs = mysql_query("show databases"); while($arr=mysql_fetch_array($rs)){ echo "


    "; mysql_select_db("$arr[0]"); $rs2 = mysql_query("show tables"); while($arr2=mysql_fetch_array($rs2)){ if($do_analyze){ $rs3 = mysql_query("analyze table `$arr2[0]`"); echo mysql_error(); $arr3=mysql_fetch_array($rs3); } if($do_repair){ $rs4 = mysql_query("repair table `$arr2[0]`"); echo mysql_error(); $arr4=mysql_fetch_array($rs4); } echo "
  1. $arr2[0] $arr3[3] $arr4[3]"; } echo "
"; }
Download repair_all_databases_with_PHP.zip797 bytes


Thank you very much! This is

Thank you very much! This is exactly what I am looking for since last week. I will try to edit code to use it with Postgresql too.

Thank you very much!!!!!!!!

Thank you very much!!!!!!!!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <pre> <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <style><img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • You may insert videos with [video:URL]

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image. is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.