Mysql使用profile分析sql开销的代码


本文摘自PHP中文网,作者不言,侵删。

本篇文章给大家带来的内容是关于Mysql使用profile分析sql开销的代码,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

Mysql使用profile分析sql开销

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

1.使用之前先查看当前数据库的版本信息,低版本无法使用.

    show version();  或者 show variables like '%version%'

2.查看profiling

    show variables like '%profil%'    ;

 

    result:

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

        | Variable_name          | Value | 

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

        | have_profiling         | YES   |   --只读变量,用于控制是否由系统变量开启或禁用profiling 

        | profiling              | OFF   |   --开启SQL语句剖析功能 

        | profiling_history_size | 15    |   --设置保留profiling的数目,缺省为15,范围为0至100,为0时将禁用p

 

    show profiles; 查看是否开启,效果同上.

3.查看使用说明

    help profile;

4.开启profile

    set profiling=1; 赋值时候不要有多余的空格.

5.运行sql,查看对应的profile

    select * from test ;

    show profiles;           

 

    result:

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

    | Query_ID | Duration   | Query                                                                                                                    |

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

    |       28 | 0.00033575 | select * from test                                                                                        |

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

 

    分析sql性能,分析的时候可以加上对应的开销字段

    show profile [cpu,io][all] for query 28 ;

 

    show profile for query 28 ;

 

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

    | Status               | Duration |

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

    | starting             | 5.7E-5   |

    | checking permissions | 7E-6     |

    | Opening tables       | 1.7E-5   |

    | init                 | 2.3E-5   |

    | System lock          | 8E-6     |

    | optimizing           | 5E-6     |

    | statistics           | 1.1E-5   |

    | preparing            | 9E-6     |

    | executing            | 3E-6     |

    | Sending data         | 8.8E-5   |

    | end                  | 5E-6     |

    | query end            | 6E-6     |

    | closing tables       | 5E-6     |

    | freeing items        | 7.8E-5   |

    | cleaning up          | 1.5E-5   |

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

6.关闭

    set profiling=off;

以上就是Mysql使用profile分析sql开销的代码的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

mysql修改root密码的四种方法介绍

删除mysql服务失败怎么办?

mysql存储引擎:myisam和innodb的区别

mysql子查询是什么

mysql多表查询详解下

安装mysql服务启动失败的原因

mysql服务启动不了解决方案

mysql 的10大经典优化案例场景实战

关于mysql中sql mode的查看与设置

mysql如何支持gbk编码

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...