Posts Tagged MySQL

Repairing tables on MySQL

 

MySQL fix

If for any reason you come across next message when querying a table:

mysql> select * from data_values_queued;
ERROR 1194 (HY000): Table 'data_values_queued' is marked as crashed and should be repaired

You can fix this problem as follow.

CHECK TABLE

First, proceed to check the table to determine the problem:

mysql> check table data_values_queued;
+----------------------------+-------+----------+----------------------------------------------------------+
| Table                      | Op    | Msg_type | Msg_text                                                 |
+----------------------------+-------+----------+----------------------------------------------------------+
| datbas1.data_values_queued | check | warning  | 4 clients are using or haven't closed the table properly |
| datbas1.data_values_queued | check | error    | Size of datafile is: 4200         Should be: 4220        |
| datbas1.data_values_queued | check | error    | Corrupt                                                  |
+----------------------------+-------+----------+----------------------------------------------------------+
3 rows in set (0.05 sec)

Here you can see the table wasn’t closed properly, for instance due to a abrupt shutdown. In my case a discard the first message because I’m using InnoDB as engine, which allows concurrency on tables.

REPAIR TABLE

Now for repairing the table you can use the following sentence:

mysql> repair table data_values_queued ;
+----------------------------+--------+----------+----------------------------------------+
| Table                      | Op     | Msg_type | Msg_text                               |
+----------------------------+--------+----------+----------------------------------------+
| datbas1.data_values_queued | repair | warning  | Number of rows changed from 144 to 143 |
| datbas1.data_values_queued | repair | status   | OK                                     |
+----------------------------+--------+----------+----------------------------------------+
2 rows in set (0.00 sec)

 

With this you will have repaired the table . Let’s check it:

mysql> select * from data_values_queued;
+---------+--------+----------+---------------------+
| id      | iodbId | value    | timestamp           |
+---------+--------+----------+---------------------+
| 1476194 |    170 | 297      | 2012-01-11 08:40:45 |
| 1476193 |    170 | 296      | 2012-01-11 08:40:17 |
| 1476176 |     71 | 11692    | 2012-01-11 05:06:46 |
| 1476177 |     72 | 12061    | 2012-01-11 05:06:46 |
| 1476178 |     73 | 11820    | 2012-01-11 05:06:46 |
| 1476179 |    107 | 11703    | 2012-01-11 05:06:46 |
...
| 1476258 |    170 | 282      | 2012-01-11 11:07:43 |
+---------+--------+----------+---------------------+
143 rows in set (0.00 sec)

References

,

No Comments