Possible causes MySQL slow queries and Solutions

Have high-performance MySQL service, not only need to design a good database table structure, a good index, also you need to have good query.

In other words, the slow emergence of a query, you can proceed in terms of server, database table structure, indexes, queries and so on.

The query performance analysis, there are two ways, one is to analyze server load, the other is the analysis of a single query.

 

1. The analysis server load

 

1.1 capture slow queries

The slow query log. Slow query log is the highest measured the lowest cost, precision tools query time, and I / O overhead is negligible.

But if the long-term open slow query log, log rotation should be deployed (log rotation) tool. Or only open during the collection of the sample load.

There is also a MySQL query log, called the common log, record when a query request to the server.

 

1.2 Analysis Query Log

Use pt-query-digest analysis reports can be generated from the slow query log. After determining the need to optimize the query, you can quickly check the implementation of the query using the generated reports.

 

2. The analysis of a single query

There are three practical methods: SHOW SATUS, SHOW PROFILE, check the slow query log entries.

2.1 SHOW PROFILE

When a query is submitted to the server, this tool will record the profile information to a temporary table, and to query a given integer identifier 1 from the beginning.

Each step of the analysis report will be given query execution and time spent.

2.2 Use SHOW STATUS

SHOW STATUS returned some of the counters, both server-level global server, but also a session-level connection of counter based. You can show how often certain activities such as reading index, but can not give consumes much time. Guess what operations for higher operating costs or more time consuming.

2.3 The slow query log

Includes SHOW PROFILE and SHOW STATUS output of all, there is more information.

2.4 Performance Schema

 

3. Performance Profiling

Slow query log is recorded to have to query the problem of slow, there may be other things that consume system resources, it could be some type of lock contention or blocking the progress of the inquiry.

 

4. DIAGNOSIS FOR INTERMITTENT

 Some possibilities:

1. to obtain data from external services running very slow

2. The cache of some important entry expired, resulting in a large number of requests fell on MySQL to rebuild the cache entry.

3.DNS inquiry occasional timeouts

4, due to the mutex contention or too low efficiency of internal caching algorithms to delete, MySQL query cache may result in service by a brief pause

 

Judgment is a single query server problem or issue

 

Guess you like

Origin www.cnblogs.com/earsonlau/p/11370225.html