启用慢查询
mysql> set long_query_time=1; -- 修改慢查询时间,只能当前会话有效;
mysql> set global slow_query_log='ON';-- 启用慢查询 ,加上global,不然会报错的;
确认
show variables like "%slow%";-- 是否开启慢查询;
show status like "%slow%"; -- 查询慢查询SQL状况;
show variables like "long_query_time"; -- 慢查询时间
测试一个慢查询
mysql> select sleep(3);
mysql> show status like '%slow%';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| Slow_launch_threads | 0 |
| Slow_queries | 1 |
+---------------------+-------+
-- Slow_queries 一共有一条慢查询
RDS设置一个params group
内容如下:参照aws rds的文档:
https://docs.aws.amazon.com/zh_cn/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html
注意 log out 选择为file
重启RDS来生效
显示如下:
# Time: 180409 7:06:04
# User@Host: dbu[dbu] @ [172.31.30.197] Id: 12
# Query_time: 3.000339 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1523257564;
select sleep(3);