如下图,表中明明有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 是个粗略的统计数据,并不保证准确,具体的行数使用selct count(xxx)获得。
如果查出来为0,就表示表中实际行数就是0了。
你的这种情况我还原下:
你开启事务,然后不停的插入数据,插入2万多条的数据,这个时候show table status中的rows 就看到你插入的2万多条数据,但是你不小心关掉了x掉了窗口,导致事务没有提交,实际表中是没有这些数据的(mysql 不会很智能的更新rows的条数,它只是一个粗略的统计而已,没有必要)。