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 | +------------+
Copy after login -
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 | +------------------------+-------+
Copy after login -
Enable profile:
mysql> set profile=1;
Copy after login -
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;
Copy after login -
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` | +----------+------------+--------------------------------------------------------------------------------------------------------+
Copy after login -
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 | +----------------------+----------+
Copy after login -
Close profile:
mysql> set profiling=0;
Copy after login -
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;
Copy after login
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分析
Copy after login
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!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings

The methods for viewing SQL database errors are: 1. View error messages directly; 2. Use SHOW ERRORS and SHOW WARNINGS commands; 3. Access the error log; 4. Use error codes to find the cause of the error; 5. Check the database connection and query syntax; 6. Use debugging tools.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.
