Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4991

Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4993
Question 76: How do you repair the table? – MySQL Question of the Day

Skip to content

By plogi in mysql questions

Now we create and break a table:

drop table if exists t1;
set @a:=0;
create table t1 (primary key (tid),index(ttype,tdate))
  engine=myisam
  select @a:=@a+1 as tid,rand()*99999999 as tsum, floor(rand()*3) as ttype,
         adddate('2010-01-01',interval rand()*360 day) as tdate
  from information_schema.columns, information_schema.tables limit 40000 ;
create table if not exists break_it like t1;
flush tables;

select concat(@@global.datadir,database()) as dbdir;


 
While keeping the mysql session open, go to the dbdir directory and delete t1.MYI .
Then copy break_it.MYI to t1.MYI .
In the mysql session, issue a “check table t1;”

you should see something like this:

MariaDB [tt]> check table t1;
+-------+-------+----------+-------------------------------------------------+
| Table | Op    | Msg_type | Msg_text                                        |
+-------+-------+----------+-------------------------------------------------+
| tt.t1 | check | warning  | Table is marked as crashed                      |
| tt.t1 | check | warning  | Size of datafile is: 1693848       Should be: 0 |
| tt.t1 | check | error    | Record-count is not ok; is 45360   Should be: 0 |
| tt.t1 | check | warning  | Found 45360 key parts. Should be: 0             |
| tt.t1 | check | error    | Corrupt                                         |
+-------+-------+----------+-------------------------------------------------+
5 rows in set (0.12 sec)


How do you repair it again?

a) fix table t1;
b) alter table t1 engine myisam;
c) repair table t1;
d) optimize table t1;

 
[MyISAM table maintenance - Investigate and repair broken tables]

Tags: , ,

Comment Feed

One Response

  1. plogi1. July 2010 @ 19:32:19


    c

    FIX TABLE does not exist. With the ALTER and OPTIMIZE there is a catch: if the table has been marked as crashed (like in the example with a crash), then the ALTER and OPTIMIZE will cause an implicit REPAIR. If the table wasn’t marked as crashed, then those operations might cause the table data to be lost!

You must be logged in to post a comment.