Record mysql Tuning

Source: Internet
Author: User

Symptom

Mysql CPU usage: 188% (multi-core)

Solution

1. Slow Query

Vi/etc/my. cnf Add the following content under mysqld:
 

Log-slow-queries = slow. log
Long_query_time = 5

It means to record the SQL to slow. log for more than 5 seconds.
Find the content of slow. log and find that there are a large number of SQL statements in it. Below are several SQL Optimization Principles
A) create an index on the fields in the where statement. Assume that the following SQL statement is the content of slow. log.
Select count (*) from table where table_column = 'test'

You need to create an index for the table_column (this is only a common rule. For details, please go to the Internet to check the rules)

After the index is created, modify the mysql parameters.

2. Adjust mysql Parameters

Vi/etc/my. cnf

Add the following under [mysqld ]:
Tmp_table_size = 1024 M

Restart mysql after adding it, And then observe it. If the load is still high, you can increase it accordingly. After I adjust this parameter to 2048, the load will be down.

This parameter value should be treated according to specific circumstances, and there is no specific value.

So what is the purpose of this parameter? Why is it so amazing? Haha, when executing a query, If SQL performs group by or orderby on the query, it will put the result set in this space. Therefore, if this parameter is small, the above problem will occur ~~

 

Related Article

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.