Again, we’ll create and then break a table. Follow the instructions below:
drop table if exists t1;
create table t1 (tid bigint not null auto_increment,
ttype int,
tsum double,
tdate date,
primary key (tid),index(ttype,tdate))
engine=myisam;
insert into t1 select null,rand()*99999999,floor(rand()*3),
adddate('2010-01-01',interval rand()*360 day)
from information_schema.columns,
information_schema.tables limit 40000 ;
flush tables;
select concat(@@global.datadir,database()) as dbdir;
While keeping the mysql session open, go to the dbdir directory and delete 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 | Error | Can't find file: 't1' (errno: 2) |
| tt.t1 | check | status | Operation failed |
+-------+-------+----------+----------------------------------+
2 rows in set (0.00 sec)
Note, that a “REPAIR TABLE t1;” will not repair the table this time (try it!).
Pick from the options below everything that needs to be done in order to repair this table.
a) mysqladmin -p -u root shutdown b) repair table t1 index_rebuild; c) repair table t1 use_frm; d) repair table t1 extended; e) repair table t1 quick;
[MyISAM table maintenance - Investigate and repair broken tables]
c
Only the “USE_FRM” option of the REPAIR will help you now.“.
Use this option only as a last resort.
Afterwards, use “SHOW TABLE STATUS” to check the amount of rows and the auto_increment.
If necessary, adjust the value with “ALTER TABLE t1 AUTO_INCREMENT=
As with any REPAIR, make a copy of the table-files first – so that you have something left, in case the REPAIR emtpies your table.