mysql 慢查詢日誌記錄

環境:mysql

  操做系統: CentOS  6.5sql

  數據庫:    mysql-5.1.73數據庫

一、查看當前慢查詢配置socket

mysql> show variables like 'slow%';
+---------------------+---------------------------------+
| Variable_name       | Value                           |
+---------------------+---------------------------------+
| slow_launch_time    | 2                               |
| slow_query_log      | OFF                             |
| slow_query_log_file | /var/run/mysqld/mysqld-slow.log |
+---------------------+---------------------------------+
3 rows in set (0.00 sec)

二、經過修改 my.cnf 開啓監聽慢查詢測試

 vi /etc/my.cnf
 
 添加配置

[mysqld]
log-slow-queries = /var/lib/mysql/sql_slow.log
#單位秒
long_query_time = 1
log-queries-not-using-indexes

三、從新啓動 mysqlspa

service mysqld restart

四、查看配置是否生效操作系統

mysql> show variables like 'slow%';
+---------------------+-----------------------------+
| Variable_name       | Value                       |
+---------------------+-----------------------------+
| slow_launch_time    | 2                           |
| slow_query_log      | ON                          |
| slow_query_log_file | /var/lib/mysql/sql_slow.log |
+---------------------+-----------------------------+
3 rows in set (0.00 sec)

五、測試日誌是否記錄rest

執行SQL:日誌

     select sleep(3);

  查看記錄日誌 tail  -300f  sql_slow.log code

 Query_time :查詢使用時間

Lock_time:鎖時間
Rows_sent:返回記錄條數
Rows_examined:總共記錄條數

    Tcp port: 3306  Unix socket: /var/lib/mysql/mysql.sock
    Time                 Id Command    Argument
    # Time: 151019 15:39:04
    # User@Host: [root] @ localhost []
    # Query_time: 3.001364  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 0
    SET timestamp=1445240344;
    select sleep(3);
相關文章
相關標籤/搜索