`
hongtoushizi
  • 浏览: 360463 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

mysql profile使用

阅读更多

转载自:http://hi.baidu.com/%C2%ED%B3%A4%D5%F72008/blog/item/3f8ec3fd9afe348fb801a0c5.html

mysql的sql语句优化都使用explain,但是这个没有办法知道详细的Memory/CPU等使用量
MySQL Query Profiler, 可以查询到此 SQL 语句会执行多少, 并看出 CPU/Memory 使用

量, 执行过程 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;
关闭此功能

mysql> set profiling=0;
mysql> show variables like 'profiling%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| profiling              | OFF   |
| profiling_history_size | 15    |
+------------------------+-------+

 

 

分享到:
评论

相关推荐

    Mysql Profile

    asp.net2.0的Membership用户角色权限功能只支持mssql,access.这个是Mysql的支持!仅供参考!

    MySqlProfile

    共有四個文件,三個cs文件,另一個為安裝說明.

    mysql中profile的使用方法教程

    当我们要对某一条sql的性能进行分析时,可以使用它。 Profiling是从 mysql5.0.3版本以后才开放的。 启动profile之后,所有查询包括错误的语句都会记录在内。 关闭会话或者set profiling=0 就关闭了。(如果将...

    Windows下Neor Profile SQL 配置监控centos(linux)mysql详细步骤

    Windows下Neor Profile SQL 配置监控centos(linux)mysql详细步骤

    MySQL中使用SHOW PROFILE命令分析性能的用法整理

    主要介绍了MySQL中使用show profile命令分析性能的用法整理,show profiles是数据库性能优化的常用命令,需要的朋友可以参考下

    MySQL性能分析工具profile使用教程

    分析SQL执行带来的开销是优化SQL的重要手段。在MySQL数据库中,可以通过...本文描述了如何使用MySQL profile,不涉及具体的样例分析。 1、有关profile的描述 代码如下: –当前版本  root@localhost[sakila]> show v

    在Windows安装MySQL的图示指南

    本指南的目标是让那些刚接触MySQL的Windows开发者、系统管理员和微软SQL Server DBA能够简单的入门MySQL。本文用通俗易懂的方式引导你通过一些必要的步骤和工具在Windows上快速启动并运行MySQL。本指南的目的是让你...

    2021年MySQL高级教程视频.rar

    ├第一天视频,网盘文件,永久连接 01.MySQL高级课程内容介绍.mp4 02.MySQL高级Linux上安装MySQL.avi 03.MySQL高级启动及登录...16.MySQL高级优化SQL步骤showprofile.avi 17.MySQL高级优化SQL步骤trace工具.avi 18. .....

    mysql lunix的安装

    这个是MySQL5.5再contos6下的安装方法 MySQL 是...索引的优化策略,了解innodb和myisam存储引擎,熟悉MySQL锁机制,能熟练配置MySQL主从复制,熟练掌握explain、show profile、慢查询日志等日常SQL诊断和性能分析策略。

    尚硅谷Java视频教程_MySQL高级视频

    尚硅谷_MySQL高级_用Show Profile进行sql分析 · 52.尚硅谷_MySQL高级_全局查询日志 · 53.尚硅谷_MySQL高级_数据库锁理论概述 · 54.尚硅谷_MySQL高级_读锁案例讲解 · 55.尚硅谷_MySQL高级_读锁案例讲解2 · ...

    mysql高级视频教程百度云(2019).txt

    51.MySQL高级_用Show Profile进行sql分析.avi 50.MySQL高级_批量插入数据脚本.avi 49.MySQL高级_慢查询日志.avi 48.MySQL高级_为排序使用索引OrderBy优化.avi 47.MySQL高级_in和exists.avi 46.MySQL高级_...

    mysql-5.7.28-macos10.14-x86_64.dmg

    执行vim ~/.bash_profile 在文件中添加mysql/bin的目录 按i编辑 PATH=$PATH:/usr/local/mysql/bin 按esc,然后输入:wq保存。 最后在命令行输入source ~/.bash_profile  登录 mysql -u root -p 系统自动生成的密码...

    2018最新Mysql高级视频教程

    MySQL是目前流行的关系型数据库管理系统,在WEB...索引的优化策略,了解innodb和myisam存储引擎,熟悉MySQL锁机制,能熟练配置MySQL主从复制,熟练掌握explain、show profile、慢查询日志等日常SQL诊断和性能分析策略。

    mac版 mysql-5.6.39 安装包

    安装MySQL 一键到底 配置MySQL 进入系统偏好设置 -> MySQL -> Start MySQL Server 配置环境变量 vim ~/ .bash_profile 写入:export PATH=${PATH}:/usr/local/mysql/bin 运行一下这个配置:source ~/....

    mysql-8.0.20-macos10.15-x86_64.tar.gz

    如果使用 Navicat连接MySQL Server8.0版本时出现Client does not support authentication protocol requested by server; 解决办法: mysql> use mysql; mysql> alter user 'root'@'localhost' identified with ...

    MySql 语法使用说明书

    Added MySqlScript class for executing SQL scripts Added MySqlBulkLoader class for easily loading large amounts of data Changed to recommending @ as parameter marker BINARY(16) columns are now ...

    MySQL使用profile查询性能的操作教程

    主要介绍了MySQL使用profile查询性能的操作教程,不仅是SQL语句的性能,更能够收集系统运行的CPU及内存占用情况,需要的朋友可以参考下

Global site tag (gtag.js) - Google Analytics