What is a profile? We can use it when we want to analyze the performance of a certain SQL. Profiling is only available after MySQL 5.0.3. After starting the profile, all queries including incorrect statements will be recorded. Close the session or set profiling=0 to close it. (If you set the profiling_history_size parameter to 0, this also has the effect of turning off MySQL profiling.) This tool can be used to query the SQL execution status, how much time is spent on System lock and Table lock, etc. It is very important to locate the I/O consumption and CPU consumption of a statement. (The two largest resources consumed by SQL statement execution are IO and CPU) --After MySQL 5.7, profile information will be gradually abandoned. MySQL recommends using performance schema MySQL official website definition
Simply put, the current session resource consumption. Note: show profile and show Profiles are not recommended and may be deleted in later versions of MySQL; the official website recommends using Performance Schema How to use The profile is disabled by default and is recommended for production environments. View the profile settings of the current environment mysql> show variables like '%profiling%'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | have_profiling | YES | | profiling | OFF | | profiling_history_size | 15 | +------------------------+-------+ profiling off means profiling is turned off, and profiling_history_size 15 means saving the resource consumption of the most recent 15 SQL statements. To enable the profile function, you can use the command set global profiling = 1; Then you can use the following command show profiles; View the latest 15 SQL statements; If you want to view the specific situation of a certain item, the SQL format is: SHOW PROFILE [type [, type] ... ] [FOR QUERY n] [LIMIT row_count [OFFSET offset]] type: { ALL | BLOCK IO | CONTEXT SWITCHES | CPU |IPC | MEMORY | PAGE FAULTS | SOURCE | SWAPS } The official website explains each field in type as follows:
Profiling is valid for each session. When the session ends, the current profiling information will be lost. Use Cases mysql> show profiles; +----------+------------+----------------------------+ | Query_ID | Duration | Query | +----------+------------+----------------------------+ | 1 | 0.00060275 | select * from customers | | 2 | 0.00222450 | show tables | | 3 | 0.00567425 | select * from offices | | 4 | 0.00052050 | show tables | | 5 | 0.01123300 | select * from payments | | 6 | 0.00111675 | show tables | | 7 | 0.02049625 | select * from productlines | +----------+------------+----------------------------+ When troubleshooting SQL execution, or which SQL is executing very slowly and where it is slow, profiles are very useful tools. Shows where a SQL statement is spent mysql> show profile for query 7; +----------------------+----------+ | Status | Duration | +----------------------+----------+ | starting | 0.000043 | | checking permissions | 0.000005 | | Opening tables | 0.014552 | | init | 0.000025 | | System lock | 0.000009 | | optimizing | 0.000004 | | statistics | 0.000011 | | preparing | 0.000010 | | executing | 0.000003 | | Sending data | 0.005653 | | end | 0.000010 | | query end | 0.000009 | | closing tables | 0.000020 | | freeing items | 0.000121 | | cleaning up | 0.000023 | +----------------------+----------+ The information is clear at a glance, so I can get a general understanding of the SQL execution. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: Vue Element UI custom description list component
>>: How to set up ssh password-free login to Linux server
Ubuntu 16.04 installs the PHP7.0 environment by d...
MyISAM, a commonly used storage engine in MySQL c...
1. Install mysql5.6 docker run mysql:5.6 Wait unt...
Preface Recently, when using MySQL 6.0.x or highe...
Includes the process of initializing the root use...
Today, when I was building a redis environment in...
Inline format <colgroup>...</colgroup>...
Table of contents Overview Method 1: Pass paramet...
Table of contents Preface Solution: Step 1 Step 2...
Copy code The code is as follows: <select> ...
By chance, I discovered that a SQL statement prod...
Generally, the colspan attribute of the <td>...
In Black Duck's 2017 open source survey, 77% ...
Preface We already know that MySQL uses the SQL S...
jQuery realizes the effect of theater seat select...