mysql - mysql监控sql语句运行时间

1.show profiles

(1)查看MySQL版本

Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后。

show variables like “%version%”; 或者 select version();查看MySQL版本

(2)开启profile

确定支持show profile 后,查看profile是否开启,数据库默认是不开启的。

变量profiling是用户变量,每次都得重新启用。

查看方法: show variables like “%pro%”;

设置开启方法: set profiling = 1;

(3)执行业务SQL后,再执行show profiles;即可查看到执行时间

(4)关闭,执行set profiling=0;

2.timestampdiff

三条sql语句要连一起执行

set @d=now();

select * from comment;

select timestampdiff(second,@d,now());

若用命令行来执行,要在select timestampdiff(second,@d,now());

后面放一空行,不然最后一个sql要按回车执行。

猜你喜欢

转载自blog.csdn.net/helunqu2017/article/details/113816026