Performance Analysis of Profiling in Mysql

Source: Internet
Author: User

MySQL 5.0.37 and later versions support Profiling-official manual. This tool can be used to query how much time the SQL statement executes, how much time the System lock and Table lock take, and so on. It is very important to locate the I/O consumption and CPU consumption of a statement.
All queries after profile is started, including statements with errors, are recorded.
Close the session or set profiling = 0.
# Enable profiling
Mysql & gt; set profiling = 1;
Mysql & gt; select * from user limit 1;
Mysql & gt; select count (*) from user group by sexal;
# View the profile of these statements
Mysql & gt; show profiles;
+ -------------- + ---------------- + ---------------------------------------------------------------- +
| Query_ID | Duration | Query |
+ -------------- + ---------------- + ---------------------------------------------------------------- +
| 1 | 1 | 0.00013200 | select database () |
| 2 | 0.00044100 | select * from user limit 2 |
| 3 | 1.95544100 | select nick, count (*) from user group by online |
+ -------------- + ---------------- + ---------------------------------------------------------------- +
View the profiles of a specific (Query_ID = 3) statement, including CPU and plunger I/O
Mysql> show profile cpu, block io for query 3;
+ ---------------------- + ---------- + ------------ + -------------- + --------------- +
| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+ ---------------------- + ---------- + ------------ + -------------- + --------------- +
| Starting | 0.000057 | 0.000000 | 0.000000 | 0 | 0 |
| Opening tables | 0.000014 | 0.000000 | 0.000000 | 0 | 0 |
| System lock | 0.000006 | 0.000000 | 0.000000 | 0 | 0 |
| Table lock | 0.000009 | 0.000000 | 0.000000 | 0 | 0 |
| Init | 0.000021 | 0.000000 | 0.000000 | 0 | 0 |
| Optimizing | 0.000006 | 0.000000 | 0.000000 | 0 | 0 |
| Statistics | 0.000011 | 0.000000 | 0.000000 | 0 | 0 |
| Preparing | 0.000010 | 0.000000 | 0.000000 | 0 | 0 |
| Creating tmp table | 0.000039 | 0.000000 | 0.000000 | 0 | 0 |
| Executing | 0.000005 | 0.000000 | 0.000000 | 0 | 0 |
| Copying to tmp table | 1.900619 | 1.030785 | 0.197970 | 127 | 127 |
| Sorting result | 0.000015 | 0.000000 | 0.000000 | 0 | 0 |
| Sending data | 0.000015 | 0.000000 | 0.000000 | 0 | 0 |
| End | 0.000005 | 0.000000 | 0.000000 | 0 | 0 |
| Removing tmp table | 0.000008 | 0.000000 | 0.000000 | 0 | 0 |
| End | 0.000005 | 0.000000 | 0.000000 | 0 | 0 |
| Query end | 0.000004 | 0.000000 | 0.000000 | 0 | 0 |
| Freeing items | 0.000025 | 0.000000 | 0.000000 | 0 | 0 |
| Logging slow query | 0.000004 | 0.000000 | 0.000000 | 0 | 0 |
| Cleaning up | 0.000005 | 0.000000 | 0.000000 | 0 | 0 |
+ ---------------------- + ---------- + ------------ + -------------- + --------------- +
The preceding figure shows the CPU and Block I/O consumption of a statement. It is convenient to locate the bottleneck. You can use the statement "Show profile *** for query 3" to obtain the remaining information.
 
Additionally, the learning material of profiling is attached.
Basics of profiling
Http://www.xaprb.com/blog/2006/10/12/how-to-profile-a-query-in-mysql/
Http://www.xaprb.com/blog/2006/10/15/a-case-study-in-profiling-queries-in-mysql/
Http://www.xaprb.com/blog/2006/10/17/mysql-profiling-case-study-part-2/
Advanced profiling
Http://www.mysqlperformanceblog.com/2009/01/19/profiling-mysql-stored-routines/
Http://www.mysqlperformanceblog.com/2008/05/18/wanted-better-memory-profiling-for-mysql/
Maatkit-perldoc mk-query-profiler
Profiling advanced
Http://dev.mysql.com/tech-resources/articles/pro-mysql-ch6.html
Http://dev.mysql.com/tech-resources/articles/using-new-query-profiler.html
Profiling hardcore
Http://www.scribd.com/doc/2669413/DTrace-and-MySQL-Presentation
Http://forge.mysql.com/wiki/Using_DTrace_with_MySQL
Http://wikis.sun.com/display/BluePrints/Optimizing+MySQL+Database+Application+Performan

From Performance Test Column

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.