MySQL: 查看一次SQL的执行时间都花在哪些环节上

select @@profiling  -- 看看当前的session的profiling打开没有

set profiling = 1  -- 如果没打开,打开一下 

 -- 执行一些sql 
select count(*) ... 

select * from ...

show profiles -- 查看所有已执行的profile

show profile for query 2  -- 看看刚才某条sql执行的具体时间拆分,2是个某个query id 

show profile cpu for query 2  -- 看看刚才某条sql执行的具体时间拆分,并加上相应的cpu信息 (cpu也可以换成all,以查看更多系统指标) 

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.