免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 17719 | 回复: 52

2G的myisam表,查询慢,如何优化?【已解决】 [复制链接]

论坛徽章:
0
发表于 2009-11-02 16:57 |显示全部楼层
2G的myisam表,查询慢,如何优化?

[ 本帖最后由 小木虫子 于 2009-11-13 10:26 编辑 ]
yejr.jpg

论坛徽章:
0
发表于 2009-11-02 17:19 |显示全部楼层
换一个好点的服务器。

论坛徽章:
0
发表于 2009-11-02 17:42 |显示全部楼层

回复 #2 Coolriver 的帖子

。。。。。。。。还有别的方法吗?

论坛徽章:
9
每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00数据库技术版块每周发帖之星
日期:2016-03-07 16:30:25
发表于 2009-11-02 19:46 |显示全部楼层
加索引~优化语句~

论坛徽章:
0
发表于 2009-11-02 20:25 |显示全部楼层
trouble shooting
找出问题

论坛徽章:
0
发表于 2009-11-02 21:03 |显示全部楼层
原帖由 小木虫子 于 2009-11-2 17:42 发表
。。。。。。。。还有别的方法吗?


你什么都不提供只说一个这样的现象,能解决什么?

能做的:
合理的配置一下MySQL,前端缓存一些能缓存的东东,去除无用的索引,加有用的索引,调整SQL语句。

论坛徽章:
0
发表于 2009-11-03 11:45 |显示全部楼层
是个网上下的留言板。

论坛徽章:
9
每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00每日论坛发贴之星
日期:2016-01-04 06:20:00数据库技术版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00IT运维版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00综合交流区版块每日发帖之星
日期:2016-01-04 06:20:00数据库技术版块每周发帖之星
日期:2016-03-07 16:30:25
发表于 2009-11-03 11:53 |显示全部楼层
用explain 先调优语句吧。
如果有困难,可以把语句,explain结果,表结构,索引情况,贴到版上,大家讨论一下。

论坛徽章:
8
综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年纪念徽章
日期:2013-10-24 15:41:34酉鸡
日期:2013-10-19 10:17:1315-16赛季CBA联赛之北京
日期:2017-03-06 15:12:44
发表于 2009-11-03 12:24 |显示全部楼层
提问的智慧很多人都没看

论坛徽章:
0
发表于 2009-11-03 13:09 |显示全部楼层
______________________________________________________________________ 001 ___
Count         : 194  (91.51%)
Time          : 1729 s total, 8.912371 s avg, 6 s to 82 s max  (75.67%)
  95% of Time : 1395 s total, 7.581522 s avg, 6 s to 15 s max
Lock Time (s) : 0 total, 0 avg, 0 to 0 max  (0.00%)
  95% of Lock : 0 total, 0 avg, 0 to 0 max
Rows sent     : 20 avg, 2 to 20 max  (0.05%)
Rows examined : 1.35M avg, 13.74k to 1.77M max  (96.53%)
Database      :
Users         :
        dev@ 10.1.1.4 : 100.00% (194) of query, 93.87% (199) of all users

Query abstract:
SELECT * FROM pw_gbook WHERE uid='S' ORDER BY postdate DESC LIMIT N,N;

Query sample:
SELECT * FROM pw_gbook WHERE uid='48' ORDER BY postdate DESC LIMIT 1758260,20;




mysql> explain SELECT * FROM pw_gbook WHERE uid='48' ORDER BY postdate DESC LIMIT 1758260,20;
+----+-------------+----------+------+---------------+------+---------+-------+---------+-------------+
| id | select_type | table    | type | possible_keys | key  | key_len | ref   | rows    | Extra       |
+----+-------------+----------+------+---------------+------+---------+-------+---------+-------------+
|  1 | SIMPLE      | pw_gbook | ref  | uid           | uid  | 3       | const | 1781796 | Using where |
+----+-------------+----------+------+---------------+------+---------+-------+---------+-------------+
1 row in set (0.02 sec)

mysql> desc pw_gbook;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1547955
Current database: gbook

+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | int(11)      | NO   | PRI | NULL    | auto_increment |
| uid       | mediumint( | NO   | MUL | 0       |                |
| author    | varchar(20)  | NO   |     |         |                |
| authorid  | mediumint( | NO   |     | 0       |                |
| type      | tinyint(1)   | NO   |     | 0       |                |
| postdate  | int(10)      | NO   |     | 0       |                |
| content   | text         | NO   |     | NULL    |                |
| replydate | int(10)      | NO   |     | 0       |                |
| reply     | text         | NO   |     | NULL    |                |
+-----------+--------------+------+-----+---------+----------------+
9 rows in set (0.00 sec)

mysql> show index from pw_gbook;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1548014
Current database: gbook

+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| pw_gbook |          0 | PRIMARY  |            1 | id          | A         |     2394289 |     NULL | NULL   |      | BTREE      |         |
| pw_gbook |          1 | uid      |            1 | uid         | A         |       42755 |     NULL | NULL   |      | BTREE      |         |
| pw_gbook |          1 | uid      |            2 | postdate    | A         |     2394289 |     NULL | NULL   |      | BTREE      |         |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.00 sec)

mysql>

[ 本帖最后由 小木虫子 于 2009-11-3 13:11 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP