MySQL Database optimization

Source: Internet
Author: User
Tags time limit mysql slow query log

Different versions of MySQL optimizer have a certain difference
+ View Database version
SELECT @ @version;

+ View the database being used
Select Database ();

+ See if MySQL turns on slow query log
Show variables like ' Slow_query_log ';

+ turn on MySQL slow query log
Set global slow_query_log=on;

+ Set the file location where the MySQL slow query log is stored
Set global slow_query_log_file= '/home/mysql/sql_log/mysql-slow.log ';

+ Set non-indexed records to slow query log
Set global log_queries_not_using_indexes = on;

+ Set the time limit for SQL query logging to slow query log files, in seconds, usually 0.01s
Set long_query_time=1

+ Slow query Log analysis tool
Pt-query-digest

Pt-query-digest/var/lib/mysql/bogon-slow.log | More

+ View SQL Execution plan
Explain select * from store;
Using Filesort: Optimization is required. MySQL requires additional steps to find out how to sort the rows that are returned. It sorts all rows based on the connection type and the row pointers for all rows that store the sort key values and matching criteria.
Using Temporary: optimization is required. MySQL needs to create a temporary table to store the results, which typically occurs when an order by rather than group by is performed on a different set of columns.

MySQL Database optimization

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.