简体   繁体   中英

How to repair a MySQL table without using phpMyAdmin?

I had a table with complicated columns, I started to fill it with a heavy data, during that, it crashed.

table reported as crashed and need to be repaired.

Repair Table in phpmyadmin could not repair it.

Then I decided to start filling process again, but I even could not retrieve table structure.

How can I get data back? Or just structure?

(i run mysql under xampp/windows on a amd quad)

PHPMyadmin tends to have problems when executing long queries. If it failed to do the repair table with a specific error message, please post it. If it just hung, you shoul try the repair by using the command line version of mysql, it's located in the bin directory of your mysql installation.

mysql -u username -p
mysql> use dbname;
mysql> repair table tablename;

depending on the size of the table, this could take A while.

If that doesn't work, your next move is to use myisamchk if your table uses the MyISAM engine.

If your table is in myISAM, myisamchk is the first tool to check. It resides in the /bin directory of your mySQL installation. Here is a list of its repair options .

It's wise to make a backup copy of your data directory before running myisamchk on it, just in case.

You can also repair it in 1 or 2 simple steps if your server is working. go to phpmyadmin and checked that table which one crushed and then select Repair table option from the dropdown.

Here is where the repair button is:

在此处输入图片说明

You can use php script also like this:

<?php
    $host="localhost";
    $user="db_username";
    $password="db_password";
    $db="database_name";
    
    // connect to database
    $con = mysqli_connect($host,$user,$password);
    // select the correct database
    mysqli_select_db($con,$db);
    // get a list of the tables
    $alltables = mysqli_query($con,"SHOW TABLES;");
    
    // record the output
    $output = array();
    
    while($table = mysqli_fetch_assoc($alltables)){
     foreach($table as $db => $tablename){
      $sql = 'REPAIR TABLE '.$tablename.';';
      $response = mysqli_query($con,$sql) or die(mysqli_error($con));
      $output[] = mysqli_fetch_assoc($response);
     };
    };
    // print output
    print_r($output);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM