mysql performance profiling tool

MYSQL slow query configuration
First, we first check whether the slow query status of the MYSQL server is enabled. Execute the following command:
show variables like '%quer%';
we can see that the current log_slow_queries status is OFF, indicating that the slow query is not currently enabled.
set global slow_query_log=1;
It is very simple to enable slow query, the operation is as follows:
Add the following information in [mysqld]:
[mysqld]
log-slow-queries=/var/log/mysql-slow.log

long_query_time = 4

log-queries-not- using-indexes

long_query_time indicates that the query time exceeds a few seconds and is recorded in the log.
log-queries-not-using-indexes records queries that do not use indexes to the log


show profiles;
mysql> show profiles;

Empty set (0.00 sec)

is displayed as empty, indicating that the profiles function is disabled. Open

mysql> set profiling=1;

Query OK, 0 rows affected (0.00 sec)


Show profiles;

mysql> show profiles;
+----------+------------+---------------------+
| Query_ID | Duration   | Query               |
+----------+------------+---------------------+
|        1 | 0.00015225 | SELECT DATABASE()   |
|        2 | 0.00045175 | show databases      |
|        3 | 0.00025575 | show tables         |
|        4 | 0.00029275 | select * from test1 |
+----------+------------+---------------------+
4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 4;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000057 |
| checking permissions | 0.000010 |
| Opening tables       | 0.000023 |
| init                 | 0.000023 |
| System lock          | 0.000015 |
| optimizing           | 0.000009 |
| statistics           | 0.000017 |
| preparing            | 0.000015 |
| executing            | 0.000006 |
| Sending data         | 0.000056 |
| end                  | 0.000008 |
| query end            | 0.000011 |
| closing tables       | 0.000013 |
| freeing items        | 0.000018 |
| cleaning up          | 0.000015 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)

查看占用cpu、 io等信息呢

mysql> show profile block io,cpu for query 2;

Viewing the execution plan of the query through EXPLAIN is the result obtained through estimation, and the actual measurement result through the counter. EXPAIN has no way of knowing if a temporary table is a disk table.



Show processlist;
this method continuously captures the output of show processlist to observe whether a large number of threads are in an abnormal state or other abnormal characteristics.
Performance schema;
performance_schema provides the following functions:
1. Provides detailed information about process waiting, including locks, Mutually exclusive variables and file information;
2. Save historical event summary information to make detailed judgments for providing MySQL server performance;
3. It is very easy to add and delete monitoring event points, and you can change the monitoring cycle of the MySQL server at will , for example (CYCLE, MICROSECOND)

first show engines to confirm that the performance shcema is turned on.

mysql> use performance_schema;
mysql> show tables; The two commands

show status and show global status can view the status information of the MySQL server. Show status is for the current session, and it will be invalid after exiting. show global status is global, restarting the database or closing the database will fail. pt-query-digest pt-query-digest is a tool for analyzing mysql slow query, it can analyze binlog, general log, slowlog






The following installation can be run using
wget percona.com/get/pt-query-digest
chmod u+x pt-query-digest


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326941775&siteId=291194637