现在我用的mysql数据库里面有200多万条数据
一个表的统计查询 就用了 6 min 30.61 sec
select count(*) from audit;
+----------+
| count(*) |
+----------+
| 2319436 |
+----------+
1 row in set (6 min 30.61 sec)这样的速度也太慢了吧 ,我感觉mysql不应该这样的 ,不知道会是什么原因引起的 ,请各位大虾指点下。
一个表的统计查询 就用了 6 min 30.61 sec
select count(*) from audit;
+----------+
| count(*) |
+----------+
| 2319436 |
+----------+
1 row in set (6 min 30.61 sec)这样的速度也太慢了吧 ,我感觉mysql不应该这样的 ,不知道会是什么原因引起的 ,请各位大虾指点下。
解决方案 »
- 求一条sql语句
- mysql数据库设计的书
- mysql存储过程问题
- MYSQL utf8/gbk/big5与英文/简中/繁中的关系
- 有没有什么最简单方法 判断mysql某个数据库(如名称为aa)是否存在
- 关于MY SQ L 的数据类型
- 如何用MYSQL提取当日的信息 显示在表单中
- 请问怎么样将含有制表符“\”的文本文件导入到mysql中去?
- MySQL Administrator 和 MySQL Query Browser浏览数据库时会导致服务停止, 不知道是不是bug
- 求助,sql执行顺序,having中的聚合函数基于哪个虚拟表
- 怎么将MYSQL数据库中的数据导入ACCESS数据库
- 分组排序sql语句优化问题
show create table audit;
show index from audit;
check table audit;
+-------+------------+----------------------------+--------------+-------------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------------------------+--------------+-------------------+-----------+-------------+----------+--------+------+------------+---------+
| audit | 0 | PRIMARY | 1 | id | A | 2387362 | NULL | NULL | | BTREE | |
| audit | 1 | appname_apptype_tfgn_index | 1 | appname | A | 120 | NULL | NULL | YES | BTREE | |
| audit | 1 | appname_apptype_tfgn_index | 2 | apptype | A | 120 | NULL | NULL | YES | BTREE | |
| audit | 1 | appname_apptype_tfgn_index | 3 | groupName | A | 120 | NULL | NULL | | BTREE | |
+-------+------------+----------------------------+--------------+-------------------+-----------+-------------+----------+--------+------+------------+---------+
+-------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+----------------+----------+----------------+----------------------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+-------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+----------------+----------+----------------+----------------------+
| audit | InnoDB | 10 | Compact | 2371272 | 125 | 297861120 | 0 | 77824000 | 0 | NULL | 2009-06-23 15:32:51 | NULL | NULL | gbk_chinese_ci | NULL | | InnoDB free: 8192 kB |
+-------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+----------------+----------+----------------+----------------------+
1 row in set (3.53 sec)
check table audit;
analyze table audit; 这个在一楼已经提过了,但你没有提供这方面的信息。
+----+-------------+-------+-------+---------------+---------+---------+------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+------+---------+-------------+
| 1 | SIMPLE | audit | index | NULL | PRIMARY | 8 | NULL | 2925746 | Using index |
+----+-------------+-------+-------+---------------+---------+---------+------+---------+-------------+
1 row in set (0.00 sec)
很慢 很慢
| Table | Op | Msg_type | Msg_text |
+-------------+-------+----------+----------+
| cm_db.audit | check | status | OK |
+-------------+-------+----------+----------+
1 row in set (1 min 56.36 sec)
SELECT COUNT(ID) FROM audit 试试
这个解释对于analyze table 来说并不正确。analyze 并不检查表是否有问题,只是重新分析一下键的分布情况。
check table/ repaire table 是检查和修复的语句。
innodb的表,你就别指望能快了。在9000万行的表上,小型机运行count 也是需要几分钟甚至10几分钟的。