3、获取SQL语句的开销信息
--可以直接使用show profile来查看上一条SQL语句的开销信息 --注,show profile之类的语句不会被profiling,即自身不会产生Profiling --我们下面的这个show profile查看的是show warnings产生的相应开销 root@localhost[sakila]> show profile; +----------------+----------+ | Status | Duration | +----------------+----------+ | starting | 0.000141 | | query end | 0.000058 | | closing tables | 0.000014 | | freeing items | 0.001802 | | cleaning up | 0.000272 | +----------------+----------+ --如下面的查询show warnings被添加到profiles root@localhost[sakila]> show profiles; +----------+------------+--------------------------------+ | Query_ID | Duration | Query | +----------+------------+--------------------------------+ | 1 | 0.00253600 | show variables like '%profil%' | | 2 | 0.00138150 | select count(*) from customer | | 3 | 0.00228600 | show warnings | +----------+------------+--------------------------------+ --获取指定查询的开销 root@localhost[sakila]>show profile for query 2; +----------------------+----------+ | Status | Duration | +----------------------+----------+ | starting | 0.000148 | | checking permissions | 0.000014 | | Opening tables | 0.000047 | | init | 0.000023 | | System lock | 0.000035 | | optimizing | 0.000012 | | statistics | 0.000019 | | preparing | 0.000014 | | executing | 0.000006 | | Sending data | 0.000990 | | end | 0.000010 | | query end | 0.000011 | | closing tables | 0.000010 | | freeing items | 0.000016 | | cleaning up | 0.000029 | +----------------------+----------+ --查看特定部分的开销,如下为CPU部分的开销 root@localhost[sakila]> show profile cpu for query 2 ; +----------------------+----------+----------+------------+ | Status | Duration | CPU_user | CPU_system | +----------------------+----------+----------+------------+ | starting | 0.000148 | 0.000000 | 0.000000 | | checking permissions | 0.000014 | 0.000000 | 0.000000 | | Opening tables | 0.000047 | 0.000000 | 0.000000 | | init | 0.000023 | 0.000000 | 0.000000 | | System lock | 0.000035 | 0.000000 | 0.000000 | | optimizing | 0.000012 | 0.000000 | 0.000000 | | statistics | 0.000019 | 0.000000 | 0.000000 | | preparing | 0.000014 | 0.000000 | 0.000000 | | executing | 0.000006 | 0.000000 | 0.000000 | | Sending data | 0.000990 | 0.001000 | 0.000000 | | end | 0.000010 | 0.000000 | 0