mysql sql语句执行时间查询

第一种:show profiles 之类的语句来查看

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) 
原文地址:https://www.cnblogs.com/feng18/p/5457470.html