查看mysql语句运行时间

show profiles 之类的语句来查看

复制代码
mysql> show profiles; 
Empty set

mysql> show variables like "%pro%"; 
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| have_profiling            | YES   |
| profiling                 | OFF   |
| profiling_history_size    | 15    |
| protocol_version          | 10    |
| proxy_user                |       |
| slave_compressed_protocol | OFF   |
| stored_program_cache      | 256   |
+---------------------------+-------+
7 rows in set

复制代码

profile是没有打开的

开启profile

复制代码
mysql> set profiling=1; 
Query OK, 0 rows affected

mysql> show variables like "%pro%"; 
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| have_profiling            | YES   |
| profiling                 | ON    |
| profiling_history_size    | 15    |
| protocol_version          | 10    |
| proxy_user                |       |
| slave_compressed_protocol | OFF   |
| stored_program_cache      | 256   |
+---------------------------+-------+
7 rows in set
复制代码

测试

执行几条sql语句

复制代码
mysql> show profiles; 
+----------+------------+-----------------------------------------------------------------------+
| Query_ID | Duration   | Query                                                                 |
+----------+------------+-----------------------------------------------------------------------+
|        1 |  0.0020095 | show variables like "%pro%"                                           |
|        2 |  0.0012765 | select * from shop where shop_tradearea_id=14 and shop_fristtype=1001 |
|        3 |   0.004761 | show tables                                                           |
|        4 |  0.0360445 | show profile for query2                                               |
|        5 | 0.00023675 | set profiling=1                                                       |
|        6 | 0.36132975 | select * from account where type=4                                    |
+----------+------------+-----------------------------------------------------------------------+
6 rows in set

mysql>  show profile for query 2; 
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000107 |
| checking permissions | 1.3E-5   |
| Opening tables       | 5E-5     |
| System lock          | 2.5E-5   |
| init                 | 0.000161 |
| optimizing           | 2.5E-5   |
| statistics           | 2.8E-5   |
| preparing            | 3E-5     |
| executing            | 4E-6     |
| Sending data         | 0.000536 |
| end                  | 1E-5     |
| query end            | 4E-6     |
| closing tables       | 1.4E-5   |
| freeing items        | 0.000242 |
| logging slow query   | 6E-6     |
| cleaning up          | 2.2E-5   |
+----------------------+----------+
复制代码

 

timestampdiff来查看测试时间

mysql> set @d=now(); 
mysql> select * from comment; 
mysql> select timestampdiff(second,@d,now());

 

posted @   慕尘  阅读(275)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示