MySQL performance optimizations and common commands

Source: Internet
Author: User

1. Index the WHERE condition after the query operation select and the Sort field

2. On-demand query, which field you need to check which field, prohibit the use of "select *"

3. The database engine is best chosen InnoDB, less with myisam,myisam suitable for more queries, InnoDB suitable for inserting and updating more operations

4. Learn to analyze slow query logs

Show slow query log base information: Show variables like ' slow_query% ';

Show slow query log time: Show global variables like ' long_query_time ';

Turn on slow query log: Set global slow_query_log= ' on ';

Set the slow query log storage location: Set global slow_query_log_file= '/usr/local/mysql/data/slow.log ';

Set the query to record more than 10 seconds: set global long_query_time=1;

In the MySQL configuration file, configure the following:

[Mysqld]
Slow_query_log = On
Slow_query_log_file =/usr/local/mysql/data/slow.log
Long_query_time = 1

5. Learn to analyze Bin-log logs

Writes a log of a specific time period to the development file:

Mysqlbinlog--no-defaults--base64-output=decode-rows-v-v--start-datetime= ' 2018-05-09 09:31:30 '--stop-datetime= ' 2018-05-09 09:33:00 ' mysql-bin.000008 > demo.txt;

6. Querying information for all tables in a particular database that the database storage engine is InnoDB

Show table status from Mmj_main where engine= ' InnoDB ';

7. Modify the table's database storage engine to InnoDB

ALTER TABLE Sdb_freeze_logs ENGINE=INNODB;

MySQL performance optimizations and common commands

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.