Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Centos7-msyql- slow query optimization

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Through slow query, you can find statements with long search time and statements that do not use indexes to find bottlenecks in mysql and optimize them.

show variables like'' You can query mysql configuration information

show global status Various server running status information

mysqladmin variables -u -p You can also query system information

mysqladmin extended-status -u -p status information

----------------------------------------------------------------------

Configure slow queries

My.cnf configuration file

slow_query_log = 1 0 Close 1 Open

slow_query_log = /** **************slow-query.log slow query log location, default mysql/data

long_query_time = 1 second, set time, exceed record

log_queries_not_using_indexes records query statements that do not use indexes

This is permanent. You need to restart mysql.

set global slow_query_log = on; temporarily open in mysql

set long_query_time = 1

Temporarily open slow query

----------------------------------------------------------------------

Slow query logs can be viewed directly using commands such as vi cat, but because there may be too many commands logged, it is easier to view them using the mysqldumpslow command.

mysqldumpslow -a -s at -r log file This command counts repeated queries, followed by count:

---------------------------------------------------------------------------

profiling analysis

It will record the executed statements, and then record various information in the execution of the statements, because it will take up some resources when it is started, and it is generally used temporarily.

set profiling = 1 0 OFF 1 ON

all kinds of commands executed after opening will be recorded.

show profiles \G View logged commands

show profile for query The first few command details, there will be CPU memory disk IO and so on More detailed data

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report