mysql ----show profile

show profile:
    mysql is used to analyze the availability of resources to provide the current session statements executed consumption, it may be used to measure the tuning of sql.
    By default parameter is off, and save the results of a recent run 15 times.
    MySQL> Show Variables like '% Profil%';
        + ------------------------ + ------- +
        | variable_name | the Value |
        + ------- + ------------------------ +
        | have_profiling | YES |
        | Profiling | OFF |
        | profiling_history_size | 15 |
        + + ------- + ------------------------
        . 3 in rows SET, warning. 1 (0.01 sec)
    
    switch is turned on after the sport of sql statement to the recently executed.
    MySQL> Show Profiles;
        + ---------- + + ----------------------- -------------------- ------------ +
        | Query_ID | Duration   | Query                          |
        +----------+------------+--------------------------------+
        |        1 | 0.05794450 | show variables like '%profil%' |
        |        2 | 0.40223375 | select * from stu              |
        |        3 | 1.00215675 | select sleep(1)                |
        |        4 | 0.19771625 | show tables                    |
        |        5 | 0.15127925 | select count(*) from employee  |
        +----------+------------+--------------------------------+
        5 rows in set, 1 warning (0.00 sec)
     
     查看执行query 3是cpu 和 io的信息
    mysql> show profile cpu ,block io for query 3;
    +----------------------+----------+----------+------------+--------------+---------------+
    | Status               | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
    +----------------------+----------+----------+------------+--------------+---------------+
    | starting             | 0.000385 | 0.000000 |   0.000000 |         NULL |          NULL |
    | checking permissions | 0.000011 | 0.000000 |   0.000000 |         NULL |          NULL |
    | Opening tables       | 0.000039 | 0.000000 |   0.000000 |         NULL |          NULL |
    | init                 | 0.000013 | 0.000000 |   0.000000 |         NULL |          NULL |
    | optimizing           | 0.000016 | 0.000000 |   0.000000 |         NULL |          NULL |
    | executing            | 0.000022 | 0.000000 |   0.000000 |         NULL |          NULL |
    | User 
    | 1.000380 | 0.000000 |   0.000000 |         NULL |          NULL |
    | end                  | 0.000028 | 0.000000 |   0.000000 |         NULL |          NULL |
    | query end            | 0.000014 | 0.000000 |   0.000000 |         NULL |          NULL |
    | closing tables       | 0.000008 | 0.000000 |   0.000000 |         NULL |          NULL |
    | freeing items        | 0.000204 | 0.000000 |   0.000000 |         NULL |          NULL |
    | Logging SLOW Query | 0.000881 | 0.000000 | 0.000000 | NULL | NULL |
    | Cleaning up | of 0.000159 | 0.000000 | 0.000000 | NULL | NULL |
    + -------------------- - + ---------- + ---------- + ------------ + ------------ - + --------------- +
    13 rows in the SET, 1 warning (0.00 sec)
    
    
    Show Profile to view all the information.
    The following information then this sql there is need for optimization: If the Status results.
           coverting heap to MyISAM: too large query results, the memory is not enough.
           creating tmp table: creation of a temporary table
           copying to temp table on disk: the assignment information in memory to disk
           Locked
    MySQL> Show All Profile for Query 3;
    +----------------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+---------------+-------------------+-------------------+-------------------+-------+--------------------------+----------------------+-------------+
    | Status               | Duration | CPU_user | CPU_system | Context_voluntary | Context_involuntary | Block_ops_in | Block_ops_out | Messages_sent | Messages_received | Page_faults_major | Page_faults_minor | Swaps | Source_function          | Source_file          | Source_line |
    +----------------------+----------+----------+------------+-------------------+---------------------+--------------+---------------+---------------+-------------------+-------------------+-------------------+-------+--------------------------+----------------------+-------------+
    | starting             | 0.000385 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | NULL                     | NULL                 |        NULL |
    | checking permissions | 0.000011 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | check_access             | sql_authorization.cc |        2202 |
    | Opening tables       | 0.000039 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | open_tables              | sql_base.cc          |        5587 |
    | init                 | 0.000013 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | Sql_cmd_dml::execute     | sql_select.cc        |         661 |
    | optimizing           | 0.000016 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | JOIN::optimize           | sql_optimizer.cc     |         213 |
    | executing            | 0.000022 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | JOIN::exec               | sql_executor.cc      |         228 |
    | User sleep           | 1.000380 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | Item_func_sleep::val_int | item_func.cc         |        4989 |
    | end                  | 0.000028 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | Sql_cmd_dml::execute     | sql_select.cc        |         714 |
    | query end            | 0.000014 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | mysql_execute_command    | sql_parse.cc         |        4520 |
    | closing tables       | 0.000008 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | mysql_execute_command    | sql_parse.cc         |        4566 |
    | freeing items        | 0.000204 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | mysql_parse              | sql_parse.cc         |        5237 |
    | logging slow query   | 0.000881 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | log_slow_do              | log.cc               |        1619 |
    | cleaning up          | 0.000159 | 0.000000 |   0.000000 |              NULL |                NULL |         NULL |          NULL |          NULL |              NULL |              NULL |              NULL |  NULL | dispatch_command         | sql_parse.cc         |        2147 |
 

Published 76 original articles · won praise 21 · views 20000 +

Guess you like

Origin blog.csdn.net/shen_chengfeng/article/details/104663064