How to use profile for Mysql tuning
The content of this article is about how to use the Mysql tuning profile. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
-
When we do mysql performance analysis, there are three most commonly used methods:
(1) Slow query (analyzing SQL that has problems)
(2) Explain (shows how mysql uses indexes to process select statements and connection tables. It can help choose better indexes and write more optimized query statements)
(3) Profile (how long it will take to execute the SQL query) , and see the CPU/Memory usage, how much time Systemlock, Table lock takes during execution, etc.) This chapter mainly gives a brief overview of the profile. Use To perform performance analysis on a certain SQL statement.
Profiling is only available since mysql5.0.3. However, after mysql5.7, profile information will be gradually abandoned, and mysql recommends using performance schema.
profileThis tool can be used to query the SQL execution status, how long System lock and Table lock take, 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)
Use the profile tool
-
to view your own mysql version:
mysql> select version(); +------------+ | version() | +------------+ | 5.6.35-log | +------------+
-
Check whether the profile function is enabled (profiling=on means enabled):
mysql> show variables like '%profil%'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | have_profiling | YES | | profiling | OFF | | profiling_history_size | 15 | +------------------------+-------+
-
Enable profile:
mysql> set profile=1;
-
After opening the profile, execute the sql statement to be analyzed:
mysql> select t1.*,t2.action from pre_forum_thread as t1 left join (select a.* from pre_forum_threadmod as a,(select tid,max(dateline) as dateline from pre_forum_threadmod group by tid) as b where a.tid=b.tid and a.dateline=b.dateline) as t2 on t1.tid=t2.tid where t1.displayorder>=0 and t1.fid in (47,49) and t1.tid > 100318 and (t1.authorid =7683017 or t2.action'DWN' or t2.action is null ) order by t1.dateline desc limit 20;
-
View the generated profile information:
mysql> show profiles; +----------+------------+--------------------------------------------------------------------------------------------------------+ | Query_ID | Duration | Query | +----------+------------+--------------------------------------------------------------------------------------------------------+ | 1 | 1.37183777 | select t1.*,t2.action from pre_forum_thread as t1 | | 2 | 0.00078796 | show columns from `bbs`.`t2` | | 3 | 0.00150425 | show columns from `bbs`.`pre_forum_thread` | +----------+------------+--------------------------------------------------------------------------------------------------------+
-
Get the specified Overhead of query statement:
mysql> show profile for query 2; +----------------------+----------+ | Status | Duration | +----------------------+----------+ | starting | 0.000147 | | checking permissions | 0.000023 | | Opening tables | 0.000047 | | init | 0.000081 | | System lock | 0.000031 | | optimizing | 0.000034 | | statistics | 0.001650 | | preparing | 0.000046 | | executing | 0.000018 | | Sending data | 2.460588 | | end | 0.000041 | | query end | 0.000019 | | closing tables | 0.000022 | | freeing items | 0.000055 | | cleaning up | 0.000085 | +----------------------+----------+
-
Close profile:
mysql> set profiling=0;
-
Related specific parameters:
type: ALL --显示所有的开销信息 | BLOCK IO --显示块IO相关开销 | CONTEXT SWITCHES --上下文切换相关开销 | CPU --显示CPU相关开销信息 | IPC --显示发送和接收相关开销信息 | MEMORY --显示内存相关开销信息 | PAGE FAULTS --显示页面错误相关开销信息 | SOURCE --显示和Source_function,Source_file,Source_line相关的开销信息 | SWAPS --显示交换次数相关开销的信息 例如,想要查看cpu和io开销可以执行命令: mysql> SHOW profile CPU,BLOCK IO FOR query 2;
Summary
- ##General simple process:
(1)set profiling=1; //打开profile分析 (2)run your sql1; (3)run your sql2; (4)show profiles; //查看sql1,sql2的语句分析 (5)SHOW profile CPU,BLOCK IO io FOR query 1; //查看CPU、IO消耗 (6)set profiling=0; //关闭profile分析
The above is the detailed content of How to use profile for Mysql tuning. For more information, please follow other related articles on the PHP Chinese website!

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool