日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql profile 不记录_mysql profile使用(转)

發(fā)布時間:2024/10/8 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql profile 不记录_mysql profile使用(转) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

mysql的sql語句優(yōu)化都使用explain,但是這個沒有辦法知道詳細的Memory/CPU等使用量

MySQL Query Profiler, 可以查詢到此 SQL 語句會執(zhí)行多少, 并看出 CPU/Memory 使用

量, 執(zhí)行過程 System lock, Table lock 花多少時間等等.

mysql> show variables like 'profiling%';

+------------------------+-------+

| Variable_name????????? | Value |

+------------------------+-------+

| profiling????????????? | OFF?? |

| profiling_history_size | 15??? |

+------------------------+-------+

開啟此功能

mysql>set profiling=1;

mysql> show variables like 'profiling%';

# 此命令會讓mysql在 information_schema 的 database 建立一個 PROFILING 的

table 來記錄.

+------------------------+-------+

| Variable_name????????? | Value |

+------------------------+-------+

| profiling????????????? | ON??? |

| profiling_history_size | 15??? |

+------------------------+-------+

profiling_history_size記錄多少次查詢

mysql> show profiles;

+----------+------------+------------------------------------+

| Query_ID | Duration?? | Query????????????????????????????? |

+----------+------------+------------------------------------+

|??????? 1 | 0.00018100 | show variables like 'profiling%'?? |

|??????? 2 | 0.00020400 | show variables like 'profiling%'?? |

|??????? 3 | 0.00007800 | set profiling=1??????????????????? |

|??????? 4 | 0.00011000 | show variables like 'profiling%'?? |

|??????? 5 | 0.00002400 | select count(1) from `mrhao_stats` |

|??????? 6 | 1.52181400 | select count(*) from `mrhao_stats` |

|??????? 7 | 0.00026900 | show variables like 'profiling%'?? |

mysql> show profile for query 6;

+--------------------------------+----------+

| Status???????????????????????? | Duration |

+--------------------------------+----------+

| (initialization)?????????????? | 0.000003 |

| checking query cache for query | 0.000042 |

| Opening tables???????????????? | 0.00001 |

| System lock??????????????????? | 0.000004 |

| Table lock???????????????????? | 0.000025 |

| init?????????????????????????? | 0.000009 |

| optimizing???????????????????? | 0.000003 |

| statistics???????????????????? | 0.000007 |

| preparing????????????????????? | 0.000007 |

| executing????????????????????? | 0.000004 |

| Sending data?????????????????? | 1.521676 |

| end??????????????????????????? | 0.000007 |

| query end????????????????????? | 0.000003 |

| storing result in query cache | 0.000002 |

| freeing items????????????????? | 0.000006 |

| closing tables???????????????? | 0.000004 |

| logging slow query???????????? | 0.000002 |

+--------------------------------+----------+

17 rows in set (0.00 sec)

mysql> show profile cpu for query 6;

+--------------------------------+----------+----------+------------+

| Status???????????????????????? | Duration | CPU_user | CPU_system |

+--------------------------------+----------+----------+------------+

| (initialization)?????????????? | 0.000003 | 0??????? | 0????????? |

| checking query cache for query | 0.000042 | 0.001??? | 0????????? |

| Opening tables???????????????? | 0.00001 | 0??????? | 0????????? |

| System lock??????????????????? | 0.000004 | 0??????? | 0????????? |

| Table lock???????????????????? | 0.000025 | 0??????? | 0????????? |

| init?????????????????????????? | 0.000009 | 0??????? | 0????????? |

| optimizing???????????????????? | 0.000003 | 0??????? | 0????????? |

| statistics???????????????????? | 0.000007 | 0??????? | 0????????? |

| preparing????????????????????? | 0.000007 | 0??????? | 0????????? |

| executing????????????????????? | 0.000004 | 0??????? | 0????????? |

| Sending data?????????????????? | 1.521676 | 1.631752 | 0.036995?? |

| end??????????????????????????? | 0.000007 | 0??????? | 0????????? |

| query end????????????????????? | 0.000003 | 0??????? | 0????????? |

| storing result in query cache | 0.000002 | 0??????? | 0????????? |

| freeing items????????????????? | 0.000006 | 0??????? | 0????????? |

| closing tables???????????????? | 0.000004 | 0??????? | 0????????? |

| logging slow query???????????? | 0.000002 | 0??????? | 0????????? |

+--------------------------------+----------+----------+------------+

17 rows in set (0.00 sec)

* ALL - displays all information

* BLOCK IO - displays counts for block input and output operations

* CONTEXT SWITCHES - displays counts for voluntary and involuntary

context switches

* IPC - displays counts for messages sent and received

* MEMORY - is not currently implemented

* PAGE FAULTS - displays counts for major and minor page faults

* SOURCE - displays the names of functions from the source code, together

with the name and line number of the file in which the function occurs

* SWAPS - displays swap counts

查詢時間跟cpu的使用

mysql> select min(seq) seq,state,count(*) numb_ops,

round(sum(duration),5) sum_dur, round(avg(duration),5) avg_dur,

round(sum(cpu_user),5) sum_cpu, round(avg(cpu_user),5) avg_cpu

from information_schema.profiling

where query_id = 7

group by state

order by seq;

關(guān)閉此功能

mysql> set profiling=0;

mysql> show variables like 'profiling%';

+------------------------+-------+

| Variable_name????????? | Value |

+------------------------+-------+

| profiling????????????? | OFF?? |

| profiling_history_size | 15??? |

+------------------------+-------+

總結(jié)

以上是生活随笔為你收集整理的mysql profile 不记录_mysql profile使用(转)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。