不知道大家之前對類似如何使用MySQL查看語句運行時間的文章有無了解,今天我在這里給大家再簡單的講講。感興趣的話就一起來看看正文部分吧,相信看完如何使用MySQL查看語句運行時間你一定會有所收獲的。
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的青岡網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
方法1> 使用 show profiles 進行查看
# 查看 profile 是不是打開的,默認是不打開
mysql> show variables like "%pro%";
+------------------------------------------+-------+
| Variable_name | Value |
+------------------------------------------+-------+
| check_proxy_users | OFF |
| have_profiling | YES |
| mysql_native_password_proxy_users | OFF |
| performance_schema_max_program_instances | -1 |
| profiling | OFF |
| profiling_history_size | 15 |
| protocol_version | 10 |
| proxy_user | |
| sha256_password_proxy_users | OFF |
| slave_compressed_protocol | OFF |
| stored_program_cache | 256 |
+------------------------------------------+-------+
11 rows in set (0.01 sec)
# 開啟 profile
mysql> set profiling=1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
# 查詢所有語句的執(zhí)行時間
mysql> show profiles;
+----------+------------+----------------------------------------------------------------------------------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+----------------------------------------------------------------------------------------------------------------------------------------+
| 1 | 0.02008300 | SELECT a.* FROM (SELECT t1.*,(SELECT COUNT(*)+1 FROM a WHERE name=t1.name AND age | 2 | 0.00034425 | SELECT * FROM a | +----------+------------+----------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set, 1 warning (0.00 sec) # 即可查看第1個 sql語句 執(zhí)行的各個操作的耗時詳情 mysql> show profile for query 1; +----------------------+----------+ | Status | Duration | +----------------------+----------+ | starting | 0.000151 | | checking permissions | 0.000009 | | checking permissions | 0.000005 | | Opening tables | 0.019543 | | init | 0.000080 | | System lock | 0.000021 | | optimizing | 0.000003 | | optimizing | 0.000002 | | statistics | 0.000011 | | preparing | 0.000022 | | optimizing | 0.000009 | | statistics | 0.000009 | | preparing | 0.000008 | | statistics | 0.000007 | | preparing | 0.000003 | | executing | 0.000007 | | Sending data | 0.000006 | | executing | 0.000001 | | Sending data | 0.000033 | | executing | 0.000002 | | Sending data | 0.000021 | | executing | 0.000003 | | Sending data | 0.000008 | | executing | 0.000002 | | Sending data | 0.000006 | | executing | 0.000002 | | Sending data | 0.000007 | | executing | 0.000002 | | Sending data | 0.000007 | | executing | 0.000002 | | Sending data | 0.000007 | | executing | 0.000002 | | Sending data | 0.000005 | | executing | 0.000002 | | Sending data | 0.000014 | | end | 0.000003 | | query end | 0.000006 | | closing tables | 0.000002 | | removing tmp table | 0.000003 | | closing tables | 0.000004 | | freeing items | 0.000036 | | cleaning up | 0.000011 | +----------------------+----------+ 42 rows in set, 1 warning (0.00 sec) 方法2> 使用 timestampdiff 來查看執(zhí)行時間 mysql> DELIMITER ;; mysql> SET @d=now(); -> SELECT * FROM a; -> SELECT TIMESTAMPDIFF(second,@d,NOW());; Query OK, 0 rows affected (0.00 sec) +----+-------+------+-------+ | id | name | age | work | +----+-------+------+-------+ | 1 | name1 | 12 | work1 | | 2 | name2 | 14 | work2 | | 3 | name1 | 15 | work3 | | 4 | name1 | 16 | work4 | | 5 | name3 | 17 | work5 | | 6 | name1 | 18 | work6 | | 7 | name4 | 19 | work7 | | 8 | name1 | 22 | work8 | +----+-------+------+-------+ 8 rows in set (0.00 sec) +--------------------------------+ | timestampdiff(second,@d,now()) | +--------------------------------+ | 0 | +--------------------------------+ 1 row in set (0.00 sec) mysql> DELIMITER ; 看完如何使用MySQL查看語句運行時間這篇文章,大家覺得怎么樣?如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。
本文題目:如何使用MySQL查看語句運行時間
地址分享:http://weahome.cn/article/jpecop.html