MySQL optimization three (two simple and practical optimization methods)

Source: Internet
Author: User

I. Periodic checklists and Analysis tables

The syntax for the parse table is as follows:

ANALYZE [LOCAL | No_write_to_binlog] TABLE tbl_name [, Tbl_name] ...

This statement is used to analyze and store the keyword distribution of the table, and the results of the analysis will enable the system to get accurate statistics so that SQL can generate the correct execution plan. If the user feels that the actual execution plan is not the expected execution plan, executing the analysis table may solve the problem. During parsing, the table is locked with a read lock. This is useful for MyISAM, BDB, and InnoDB tables. For the MyISAM table, this statement is equivalent to the use of myisamchk-a, and the following example makes a table analysis of table sales:

mysql> Analyze table sales\g;

1. Row ***************************

Table:test1.sales

Op:analyze

Msg_type:status

Msg_text:ok

1 row in Set (0.01 sec)

The syntax for the checklist is as follows:

CHECK TABLE tbl_name [, Tbl_name] ... [option] ... option = {QUICK | FAST | MEDIUM | EXTENDED | CHANGED}

The purpose of the checklist is to check whether one or more tables have errors. CHECK table is useful for MyISAM and InnoDB tables. For MyISAM tables, the keyword statistics are updated, for example:

mysql> Check table sales\g;

1. Row ***************************

Table:test1.sales

Op:check

Msg_type:status

Msg_text:ok

1 row in Set (0.11 sec)

Second, the regular optimization of the table

The syntax for tuning tables is as follows:

If you have deleted a large part of the table, or if you have made many changes to a table with variable-length rows (a table with a VARCHAR, BLOB, or TEXT column), you should use the OPTIMIZE Table command for table optimization. This command merges the space fragments in the table and eliminates the wasted space caused by the deletion or update, but the OPTIMIZE Table command only works on MyISAM, BDB, and InnoDB tables.

The following example shows the process of optimizing the table sales:

mysql> optimize table sales\g;

1. Row ***************************

Table:test1.sales

Op:optimize

Msg_type:status

Msg_text:ok

2 rows in Set (0.40 sec)

Note: The table will be locked during ANALYZE, CHECK, and OPTIMIZE execution, so be sure to take the relevant action when the database is not busy.

MySQL optimization three (two simple and practical optimization methods)

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.