V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
YAFEIML
V2EX  ›  问与答

mysql 查询慢日志大牛帮分析下

  •  
  •   YAFEIML · 2015-07-20 16:52:12 +08:00 · 1860 次点击
    这是一个创建于 3418 天前的主题,其中的信息可能已经有所发展或是发生改变。
    wp程序,后台点击任意连接慢成狗,1万多点文章,下面是慢日志,大牛给讲讲咋优化下:

    /usr/local/mysql/bin/mysqld, Version: 5.5.42-log (Source distribution). started with:
    Tcp port: 3306 Unix socket: /tmp/mysql.sock
    Time Id Command Argument
    /usr/local/mysql/bin/mysqld, Version: 5.5.42-log (Source distribution). started with:
    Tcp port: 3306 Unix socket: /tmp/mysql.sock
    Time Id Command Argument
    # Time: 150720 15:44:47
    # User@Host: root[root] @ localhost []
    # Query_time: 1.731746 Lock_time: 0.000108 Rows_sent: 1 Rows_examined: 23720
    use database;
    SET timestamp=1437378287;
    SELECT * FROM wp_posts WHERE ID = 23731 LIMIT 1;
    # Time: 150720 15:44:49
    # User@Host: root[root] @ localhost []
    # Query_time: 1.490322 Lock_time: 0.000096 Rows_sent: 5 Rows_examined: 27032
    SET timestamp=1437378289;
    SELECT wp_posts.* FROM wp_posts WHERE ID IN (27042,27040,27038,27036,27034);
    # Time: 150720 15:44:51
    # User@Host: root[root] @ localhost []
    # Query_time: 1.680649 Lock_time: 0.000124 Rows_sent: 10 Rows_examined: 3076
    SET timestamp=1437378291;
    SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag', 'post_format') AND tr.object_id IN (27034, 27036, 27038, 27040, 27042) ORDER BY t.name ASC;
    2 条回复    2015-07-20 18:38:37 +08:00
    qinglangee
        1
    qinglangee  
       2015-07-20 18:35:13 +08:00
    wp_posts 表上 id 没建索引吧,建个索引试试
    CREATE INDEX wp_posts_id ON wp_posts (ID);
    YAFEIML
        2
    YAFEIML  
    OP
       2015-07-20 18:38:37 +08:00
    @qinglangee 建立了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5439 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 07:44 · PVG 15:44 · LAX 23:44 · JFK 02:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.