MySQL Performance optimization combat

Source: Internet
Author: User

Chinese New Year due to online database often too much pressure caused by the response is very slow or even panic, bite the teeth under the big determination to solve the problem of inefficiency!

First of all, because the company adhering to the principle of rapid development, frequent on-line, resulting in the neglect of performance problems! Over time, so that the system is becoming more and more slow, so if your system query statements are optimized is very good may refer to a small significance!

Extract the slow query log file, which should be under your DataDir directory

Process slow query files by program, and import slow queries from file formats into the database:

1 mysql> desc slow_query;
2 +---------------+-------------+------+-----+---------+-------+
3 | Field     | Type    | Null | Key | Default | Extra |
4 +---------------+-------------+------+-----+---------+-------+
5 | Date     | varchar(32) | NO  |   |     |    | 查询发生的时间
6 | user     | varchar(64) | NO  |   |     |    |
7 | host     | varchar(64) | NO  |   |     |    |
8 | content    | text    | NO  |   |     |    | 将Statement进行Mask后的语句,
便于Group By
9 | query_time  | int(11)   | NO  |   |     |    | 查询所用时间,直接性能指标
10 | lock_time   | int(11)   | YES |   | 0    |    | 等待锁定的时间
11 | rows_sent   | int(11)   | YES |   | 0    |    | 返回的结果行数
12 | rows_examined | int(11)   | YES |   | 0    |    | 扫描行数
13 | statement   | text    | YES |   | NULL  |    | 实际查询语句
14 +---------------+-------------+------+-----+---------+-------+

Then play your imagination in this table try to capture what you want to capture, that type of statement pressure maximum, scan the number of rows, the longest lock ...

Like what:

After optimization:

mysql> select sum(query_time)/count(*),count 
(*),sum(query_time),min(Date),Max(Date) from slow where Date>'2008-02-20 22:50:52'
and Date<'2008-02-21 17:34:35';
+--------------------------+----------+-----------------+---------------------+---------------------+
| sum(query_time)/count(*) | count(*) | sum(query_time) | min(Date)      | Max(Date)      |
+--------------------------+----------+-----------------+---------------------+---------------------+
|          5.7233 |   2197 |      12574 | 2008-02-20 22:51:16 | 2008-02-21 17:34:10 |
+--------------------------+----------+-----------------+---------------------+---------------------+
1 row in set (0.09 sec)

Before optimization:

mysql> select sum(query_time)/count(*),count(*),sum(query_time),min(Date),Max(Date) from slow 
where Date>'2008-02-17 22:50:52' and Date<'2008-02-18 17:34:35';
+--------------------------+----------+-----------------+---------------------+---------------------+
| sum(query_time)/count(*) | count(*) | sum(query_time) | min(Date)      | Max(Date)      |
+--------------------------+----------+-----------------+---------------------+---------------------+
|          2.5983 |  16091 |      41810 | 2008-02-17 22:50:58 | 2008-02-18 17:34:34 |
+--------------------------+----------+-----------------+---------------------+---------------------+
1 row in set (0.15 sec)

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.