如何知道 select 查询花费了多少时间?

How to know what the select query took time?

我有 4 个查询,我想比较它们之间的时间,有什么命令可以显示每个查询所用的时间吗?

您可以使用SHOW PROFILE Statement

使用以下方式启用它:

SET profiling = 1;

例如,我执行了如下查询:

mysql> CREATE TABLE T1 (id INT);

mysql> use gesti;

mysql> show tables;

mysql> select * from orders limit 10;


mysql> show profiles;
+----------+------------+-------------------------------+
| Query_ID | Duration   | Query                         |
+----------+------------+-------------------------------+
|        1 | 0.38483575 | CREATE TABLE T1 (id INT)      |
|        2 | 0.00039525 | SELECT DATABASE()             |
|        3 | 0.00604350 | show tables                   |
|        4 | 0.00075625 | select * from orders limit 10 |
+----------+------------+-------------------------------+
4 rows in set, 1 warning (0.00 sec)