您的位置:首页 > 数据库 > MySQL

mysql sql语句执行时间查询

2016-05-04 10:15 585 查看
[b][b]第一种:show profiles 之类的语句来查看[/b][/b]

1.查一下profile是不是打开了,默认是不打开的。

mysql> show profiles;
Empty set (0.02 sec)
mysql> show variables like "%pro%";
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| profiling | OFF |
| profiling_history_size | 15 |
| protocol_version | 10 |
| slave_compressed_protocol | OFF |
+---------------------------+-------+
4 rows in set (0.00 sec)


我查看一下profiles里面没有东西,所以公司的电脑里面profile是没有打开的,我查看了一下mysql变量,果然是OFF的。

2.开启profile

mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)


eg:

mysql> select * from test_1;
mysql> show profiles;
+----------+------------+----------------------+
| Query_ID | Duration   | Query                |
+----------+------------+----------------------+
|        1 | 0.84718100 | select * from test_1 |
+----------+------------+----------------------+
1 row in set (0.00 sec)


第二种:(通过时间差查看)

delimiter // set @d=now();
select * from comment;
select timestampdiff(second,@d,now());
delimiter ;

Query OK, 0 rows affected (1 min 55.58 sec)

+----------------------------------+
| timestampdiff(second, @d, now()) |
+----------------------------------+
|                                2 |
+----------------------------------+
1 row in set (1 min 55.58 sec)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: