Chinaunix首页 | 论坛 | 博客
  • 博客访问: 380130
  • 博文数量: 120
  • 博客积分: 5051
  • 博客等级: 大校
  • 技术积分: 1255
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-03 01:25
文章分类

全部博文(120)

文章存档

2011年(2)

2010年(11)

2009年(28)

2008年(26)

2007年(53)

我的朋友

分类: LINUX

2007-12-12 19:56:39

第一种方法:
shell> mysqlcheck -r -c -o -uuser -ppasswd db_name

第二种方法,用以下这个脚本,从网上下的,似很管用.将这个脚本放在你的web根目录下,然后从web页面运行这个脚本.
cat repair.php

/*
        [DISCUZ!] utilities/repair.php - generally repair of database
        This is NOT a freeware, use is subject to license terms

        Version: 2.0.0
        Author: Crossday (info@discuz.net)
        Copyright: Crossday Studio ()
        Last Modified: 2002/12/6 17:00
*/

error_reporting(7);
#require './config.inc.php';

$dbhost="localhost"; --->需要修改
$dbuser="root";  --->需要修改
$dbpw="";  --->需要修改
$dbname="db_name"; -->需要修改
#$table="search_profile";

mysql_connect($dbhost, $dbuser, $dbpw);
mysql_select_db($dbname);

if(!get_cfg_var("register_globals")) {
        foreach($HTTP_GET_VARS as $key => $val) {
                $$key = $val;
        }
}

function checktable($table, $loops = 0) {
  global $db, $nohtml;

   $result = mysql_query("CHECK TABLE $table");
   if(!$nohtml) {
     echo "Checking table $table";
     echo "TableOperationTypeText";
   } else {
     echo "\n>>>>>>>>>>>>>Checking Table $table\n";
     echo "---------------------------------
\n";
   }
   $error = 0;
   while($r = mysql_fetch_row($result)) {
     if($r[2] == 'error') {
       if($r[3] == "The handler for the table doesn't support check/repair") {
         $r[2] = 'status';
         $r[3] = 'This table does not support check/repair/optimize';
         unset($bgcolor);
         $nooptimize = 1;
       } else {
         $error = 1;
         $bgcolor = 'red';
         unset($nooptimize);
       }
     } else {
       unset($bgcolor);
       unset($nooptimize);
     }
     if(!$nohtml) {
       echo "$r[0]$r[1]$r[2]$r[3]";
     } else {
       echo "$r[0] | $r[1] | $r[2] | $r[3]
\n";
     }
   }
   if($error) {
     if(!$nohtml) {
       echo "Repairing table $table";
     } else {
       echo ">>>>>>>>>>>>>Repairing Table $table
\n";
     }
     $result2=mysql_query("REPAIR TABLE $table");
     if($result2[3]!='OK')
       $bgcolor='red';
     else
       unset($bgcolor);
     if(!$nohtml) {
       echo "$result2[0]$result2[1]$result2[2]$result2[3]";
     } else {
       echo "$result2[0] | $result[1] | $result2[2] | $result2[3]
\n";
     }
   }
   if(($result2[3]=='OK'||!$error)&&!$nooptimize) {
     if(!$nohtml) {
       echo "Optimizing table $table";
     } else {
       echo ">>>>>>>>>>>>>Optimizing Table $table
\n";
     }
     $result3=mysql_query("OPTIMIZE TABLE $table");
     $error=0;
     while($r3=mysql_fetch_row($result3)) {
       if($r3[2]=='error') {
         $error=1;
         $bgcolor='red';
       } else {
         unset($bgcolor);
       }
       if(!$nohtml) {
         echo "$r3[0]$r3[1]$r3[2]$r3[3]";
       } else {
         echo "$r3[0] | $r3[1] | $r3[2] | $r3[3]

\n";
       }
     }
   }
   if($error&&$loops) {
     checktable($table,($loops-1));
   }
}

if($check) {

  $tables=mysql_query("SHOW TABLES");

  if(!$nohtml) {
    echo "";
  }

  if($iterations) {
    $iterations--;
  }
  while($table=mysql_fetch_row($tables)) {

     if(substr($table[0], -8) != 'sessions') {
       $answer=checktable($table[0],$iterations);
       if(!$nohtml) {
         echo "";
       }
       flush();
     }
  }

  if(!$nohtml) {
    echo "
 
";
  }
} else {
  echo "Database Table Repair Utility for Discuz! (Require MySQL 3.23+)

".
       "This script will attempt to repair corrupted databases. While it can repair most common errors,
".
       "it can not repair everything. As a side benefit it will also optimize your tables.
".
       "This script was copyrighted by Jelsoft and modified by Crossday Studio to make it apply for Discuz!.

".
       "Usage:

".
       "iterations=x (x is the number of times you wish for the script to attempt to repair a broken table)
".
       "nohtml=1 (Output text only no html. Useful for cronjobs and you wish to receive text only)
".
       "check=1 (without this you will get this screen and no checking)

".
       "Example Usage:

".
       "repair.php?html=1&check=1 (most common usage, will check a forum and return html results)
".       "repair.php?check=1&iterations=5 (try to repair damaged tables 5 times)".
       "";
}
?>

阅读(660) | 评论(0) | 转发(0) |
0

上一篇:mysql字符集归类

下一篇:查看mysql线程

给主人留下些什么吧!~~