Several steps to optimizing the MySQL database

Source: Internet
Author: User
Tags sql error

Several steps to analyze the problem:

  1. Turn on the slow query log.

This step is to record the SQL of the slow query, to prepare for the next step, the relevant knowledge points of this step are as follows:

1. Show variables like '%slow_query_log% '; Check that the logging for the slow query is turned on.

2. Set global slow_query_log=1; Set a slow query to open.

 2. Parse the SQL statement with explain.

Ps:explain SELECT * from temp is as shown:

      

The analysis of this step will basically find out where the problem arises. Mainly see the red box of the few points (Type,key,ref,extra). You should avoid the type of all, which means that the SQL is looked up through a full table scan, and the key indicates whether the SQL actually uses the index, and null represents none. Ref means that this operation refers to those things,

such as const (constant). The Extra represents some additional information. such as using index,using filesort (file sorting, try to avoid using).

  Note : How do I see the order in which the steps are executed? If the ID is the same, execute from top to bottom. If the ID is different, the ID is large first executed.

  3. Use profile to view the SQL execution cycle, and see if there is a problem with the SQL error on which step to perform.

1. Set profiling=1; The set profile function is turned on. 2. Show Profiles: Used to view the top more than 10 MySQL queries.

      

3.show profile for Query ID;

For example: Show profile for Query 2; is to look at the execution life cycle of the second SQL,

      

4. Modify the MySQL database configuration file, this step is generally DBA operations.

This step is mainly to modify the MySQL configuration file, such as setting the size of the query buffer, and so on.

Several steps to optimizing the MySQL database

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.