A strange MySQL problem recently occurred when querying data inconsistency in MySQL. Different select statements are used to query all the data sets.
Number of records. Select * gets four records, and select field gets three records. For specific questions, see the following query results: www.2cto.com [SQL] mysql> select * from table_myisam; + ---------- + ------- + ----------- + ------ + | datetime | uid | content | type | + ---------- + ------- + ----------- + ------ + | 1 | uid_1 | content_1 | 1 | 2 | uid_2 | content_2 | 1 | 4 | uid_4 | content_4 | 1 | 3 | uid_3 | content_3 | 1 | + ---------- + ------- + --------- + ------ + 4 rows in set (0.00 sec) mysql> select uid from table _ Myisam; + ------- + | uid | + ------- + | uid_1 | uid_2 | uid_4 | + ------- + 3 rows in set (0.00 sec) only 3 rows of records are obtained through select uid, the uid = 'uid _ 3' record is lost. I was puzzled. Later I used the check table as a reminder to find the problem. [SQL] mysql> check table table_myisam; + -------------------- + ------- + ---------- + tables + | Table | Op | Msg_type | Msg_text | + -------------------- + ------- + ---------- + qitai. table_myisam | check | warning | 1 client is using or hasn' t closed the table properly | qitai. table_myisam | check | w Arning | Size of indexfile is: 2049 shoshould be: 2048 | qitai. table_myisam | check | error | Found 3 keys of 4 | qitai. table_myisam | check | error | upload upt | + -------------------- + ------- + ---------- + query data inconsistency is caused by the damage to the index file of table_myisam, the corresponding index file table_myisam.MYI is inconsistent with the data file table_myisam.MYD. Select * does not need to traverse each index. You only need to obtain the first record and access it in the order of the linked list. Therefore, the current index corruption does not affect the use of select. The select uid needs to traverse all index items, so it only gets the damaged state and three index records. The solution is to use repair table to repair table indexes. [SQL] mysql> repair table table_myisam; + tables + -------- + ---------- + | Table | Op | Msg_type | Msg_text | + -------------------- + -------- + ---------- + | qitai. table_myisam | repair | status | OK | + -------------------- + -------- + ---------- + 1 row in set (0.00 sec) after repair, you can use check table to see that the table status is normal, four records can be obtained using select * and select uid. [SQL] mysql> check table table_myisam; + tables + ------- + ---------- + | Table | Op | Msg_type | Msg_text | + -------------------- + ------- + ---------- + ------------ + | qitai. table_myisam | check | status | OK | + -------------------- + ------- + ---------- + 1 row in set (0.00 sec)