Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to simulate an error for a table so that CHECK TABLE will fail. Is there a way to simulate it so that CHECK TABLE on the table will fail ?

share|improve this question

1 Answer 1

WARNING: Before doing this, make sure you have a good backup, as you will lose data. Now is probably a good time to make sure you have binlog enabled and know how to do an point-in-time restore as well.


You can induce a corrupt table by shutting down MySQL, opening up the database file in an editor, changing/deleting a bunch of stuff, saving the file, then re-starting MySQL.

If you're using MyISAM tables, then just edit /var/lib/mysql/<db_name>/<table_name>.MYD. If you're using InnoDB and don't have innodb_file_per_table enabled, there's probably no easy way to do this. If you do have innodb_file_per_table enabled, then edit the /var/lib/mysql/<db_name/<table_name>.ibd file.

I just tested this with a MyISAM table:

mysql> check table watchdog;
+-------------------+-------+----------+-------------------------------------------------------+
| Table             | Op    | Msg_type | Msg_text                                              |
+-------------------+-------+----------+-------------------------------------------------------+
| e_d7.watchdog     | check | error    | Size of datafile is: 151154         Should be: 162296 | 
| e_d7.watchdog     | check | error    | Corrupt                                               | 
+-------------------+-------+----------+-------------------------------------------------------+
share|improve this answer
    
ErikA, I have innodb_file_per_table enabled. I'll be doing this purely for InnoDB databases only. Let me try this out. –  Bon Ami Feb 3 '12 at 6:35
    
It seems that mysql wouldn't even start when I've modified the ibd file. Why would mysql crash because of one corrupted database (I have 10 other databases) ? –  Bon Ami Feb 3 '12 at 7:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.