mysql--->profile使用

Mysql分析-profile详解

简介
  • Profiling是从 mysql5.0.3版本以后才开放的。
    启动profile之后,所有查询包括错误的语句都会记录在内。
    此工具可用来查询SQL执行状态,System lock和Table lock 花多少时间等等,
    对定位一条语句的I/O消耗和CPU消耗 非常重要。(SQL 语句执行所消耗的最大两部分资源就是IO和CPU)
  • 在mysql5.7之后,profile信息将逐渐被废弃,mysql推荐使用performance schema
使用
  • 查看profile状态:show variables like "%pro%";
  • 开启/关闭profile:set profiling = 1/0
  • 开始分析:show profiles;
    enter image description here

  • 我们还可以查询某一条,更细的执行情况:show profile for query 4; 后边的数字是query_id
  • 清除sql缓存: reset query cache;从而让我们的分析结果更准确,来得到一个客观数据结果。

猜你喜欢

转载自www.cnblogs.com/frankltf/p/8985121.html