zoukankan      html  css  js  c++  java
  • mysql 优化2 慢查询

    默认情况下mysql不记录慢查询日志,需要在启动的时候指定
     binmysqld.exe - -slow-query-log

    通过慢查询日志定位执行效率较低的SQL语句。慢查询日志记录了所有执行时间超过long_query_time所设置的SQL语句。 show variables like ‘long_query_time’; set long_query_time=2;

    配置慢查询相关设置

    [mysqld]



    slow_query_log=1
    slow_query_log_file = i:/myweb/mysql/lib/slowquery.log
    long_query_time=0.001
    log-queries-not-using-indexes

    执行一个超过2秒操作,例如:select sleep(3);日志会出现有问题的sql语句,可以根据这些sql进行修改和优化。

    I:mywebmysqlinmysqld, Version: 5.5.20-log (MySQL Community Server (GPL)). started with:
    TCP Port: 3306, Named Pipe: (null)
    Time                 Id Command    Argument
    # Time: 140412 15:57:52
    # User@Host: root[root] @ localhost [127.0.0.1]
    # Query_time: 0.500029  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 0
    use chinatupai;
    SET timestamp=1397289472;
    select sleep(0.5);
    # Time: 140412 15:58:15
    # User@Host: root[root] @ localhost [127.0.0.1]
    # Query_time: 0.294017  Lock_time: 0.002001 Rows_sent: 6620  Rows_examined: 6620
    SET timestamp=1397289495;
    select title from phphi_article;
    # Time: 140412 16:04:53
    # User@Host: root[root] @ localhost [127.0.0.1]
    # Query_time: 0.390001  Lock_time: 0.171601 Rows_sent: 10000  Rows_examined: 10000
    SET timestamp=1397289893;
    select*from db1.tb2 order by id desc limit 10000;
    I:mywebmysqlinmysqld, Version: 5.5.20-log (MySQL Community Server (GPL)). started with:
    TCP Port: 3306, Named Pipe: (null)
    Time                 Id Command    Argument
    # Time: 140412 16:08:37
    # User@Host: root[root] @ localhost [127.0.0.1]
    # Query_time: 2.513605  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 0
    use chinatupai;
    SET timestamp=1397290117;
    select sleep(2.5);
    I:mywebmysqlinmysqld, Version: 5.5.20-log (MySQL Community Server (GPL)). started with:
    TCP Port: 3306, Named Pipe: (null)
    Time                 Id Command    Argument
    # Time: 140412 16:11:00
    # User@Host: root[root] @ localhost [127.0.0.1]
    # Query_time: 2.508005  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 0
    use chinatupai;
    SET timestamp=1397290260;
    select sleep(2.5);

  • 相关阅读:
    【题解】Luogu1308 统计单词数
    【题解】Luogu1739 表达式括号匹配
    等待
    封城日记
    【题解】luoguP5717三角形分类
    【题解】LuoguP1059明明的随机数
    我是一个跳表
    【JVM故事】了解JVM的结构,好在面试时吹牛
    【JVM故事】一个Java字节码文件的诞生记
    Java多线程通关——基础知识挑战
  • 原文地址:https://www.cnblogs.com/legend-song/p/3660548.html
Copyright © 2011-2022 走看看