鍍金池/ 問答/數(shù)據(jù)庫/ Mysql的表狀態(tài)顯示有2萬多條記錄,但是count(*)顯示0

Mysql的表狀態(tài)顯示有2萬多條記錄,但是count(*)顯示0

如下圖,表中明明有2萬多條記錄,但是使用count(*)顯示0條?被鎖住了么?如何解鎖?

mysql> show table status like 'md_org' \G
*************************** 1. row ***************************
           Name: MD_ORG
         Engine: InnoDB
        Version: 10
     Row_format: Dynamic
           Rows: 26553
 Avg_row_length: 337
    Data_length: 8962048
Max_data_length: 0
   Index_length: 5832704
      Data_free: 4194304
 Auto_increment: NULL
    Create_time: 2018-08-27 11:09:17
    Update_time: NULL
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options:
        Comment:
1 row in set (0.01 sec)

mysql> select count(*) from md_org;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.04 sec)
回答
編輯回答
涼薄

謝邀。
這個select count(*) from md_org 只是個查詢,和鎖沒有關系,沒有被鎖。

Rows:26553 是個粗略的統(tǒng)計數(shù)據(jù),并不保證準確,具體的行數(shù)使用selct count(xxx)獲得。

如果查出來為0,就表示表中實際行數(shù)就是0了。


你的這種情況我還原下:
你開啟事務,然后不停的插入數(shù)據(jù),插入2萬多條的數(shù)據(jù),這個時候show table status中的rows 就看到你插入的2萬多條數(shù)據(jù),但是你不小心關掉了x掉了窗口,導致事務沒有提交,實際表中是沒有這些數(shù)據(jù)的(mysql 不會很智能的更新rows的條數(shù),它只是一個粗略的統(tǒng)計而已,沒有必要)。

2017年5月16日 19:08