Home  >  Article  >  Database  >  MySQL慢查询支持毫秒的设置_MySQL

MySQL慢查询支持毫秒的设置_MySQL

WBOY
WBOYOriginal
2016-06-01 13:42:401682browse

bitsCN.com
MySQL慢查询支持毫秒的设置  MySQL慢查询本身不支持ms级别(需要打补丁),但是对MySQL5.21+的版本,long_query_time最小值为0(5.2.1之前版本最小为1s),单位是s,如果指定ms,其ms部分会被忽略;其实这已经是变相支持毫秒级别了,比如查询时间大于100ms将被记录到slow log中;我们可以设置set global long_query_time=0.1;
 测试:
 1,直接set global long_query_time=0.1,查询时间大于0.1秒的查询都会被记录到slow log中;设置后,退出重新登录mysql> set global long_query_time=0.1;Query OK, 0 rows affected (0.00 sec)mysql> exitBye-bash-3.2$
 2, 执行一个查询为0.2s的查询,看此查询是否被记录mysql> select sleep(0.2);    +------------+| sleep(0.2) |+------------+| 0 |+------------+1 row in set (0.21 sec)# administrator command: Quit;# Time: 120412 15:39:15# User@Host: root[root] @ localhost []# Query_time: 0.202244 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0SET timestamp=1334216355;select sleep(0.2);可见在slow log里已经记录了这个查询   作者 RogerZhuo bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn