MySQL can record all slow queries and record the SQL statements in the specified file, or you can add updates through the Mysqlbinlog record, or you can restore the database through Mysqlbinlog.
MySQL Slow query record
Edit My.cnf File
Linux is
--Set the log file locationSet global slow_query_log_file =/sql_log/slow_log.log;--Set whether to enable logging without using an indexed SQLSet global log_queries_not_using_indexes = on;--Set the SQL that records execution time beyond the set value
Turn on slow query logAdd two configuration parameters under the [mysqld] line in the configuration file my.cnf or My.iniSlow_query_log = on #开启慢查询long_query_time=1 #设置慢查询时间 1 s Slow_query_log_file="d:/phpstudy/mysql/data/slow_query.log"
as we all know,MySQL Slow login manySQLThe statement structure and object are the same, except that the variables are different, for suchSQL,we can classify it as a category, count the number of executions, the average execution time ,
First, the concept part:As the name implies, the slow query log is a long execution of query, which is what we often call slow query, by setting--log-slow-queries[=file_name] to open the function and set the record location and file name, The
Installing MysqlslaSource Path: https://github.com/daniel-nichter/hackmysql.comSource Storage Path:/USR/LOCAL/SRC1. Get the source codeIf you don't have a git command, install git firstYum Install Gitcd/usr/local/srcgit clone
First, IntroductionTurn on the slow query log, you can let the MySQL record query over a specified time of the statement, through the location analysis of performance bottlenecks, to better optimize the performance of the database system.Second,
Mysql>Show variables like 'long%'; Note: This long_query_time is used to define a "slow query" that is slower than the number of seconds.+-----------------+-----------+|Variable_name|Value|+-----------------+-----------+|Long_query_time| 10.000000 |
Perform mysqldumpslow–h to view help information. Main introduction Two parameters-S and-t-S This is a sort parameter, optional:Al: Average lockout timeAR: Average number of returned recordsAt: Average query timeC: CountL: Lockout timeR: Return
MySQL Slow queryFirst, check the system all parameter status:Mysql> Show variablesSecond, see the definition of slow query:Mysql> Show variables like '%quer% ';| log_slow_queries | On || Long_query_time | 5.000000 |Mysql> Show variables like ' slow%
System performance tuning in particular MySQL database tuning a primary basis is the slow query log. Originally there is a powerful tool on Ubantu or CentOS is Percona Toolkit, then how to use Pt-query-digest on Mac?Download Percona ToolkitAccess
Found that there is a tool mysqlsla, analysis query log than Mysqldumpslow analysis will be more clear!Install Mysqlsla:Download mysqlsla-2.03.tar.gz[Email protected] export]# TAR-XVF mysqlsla-2.03.tar.gz[email protected] export]# Yum install *dbi*[
MySQL Slow query configurationMySQL logs all SQL statements that execute more than the set time threshold of the Long_query_time parameter, and the slow query log is the SQL logTurn on Slow Query methodMethod One,In the MySQL config file (under
Found that there is a tool mysqlsla, analysis query log than Mysqldumpslow analysis will be more clear!Install Mysqlsla:Download mysqlsla-2.03.tar.gz[Email protected] export]# TAR-XVF mysqlsla-2.03.tar.gz[email protected] export]# Yum install
To view the current slow-scan log status: Show variables like '%slow% '; #主要关注三个变量: Slow_query_log #是否启用slow_query_log_file #日志文件 # time threshold for slow check show variables like ' Long_ Query_time '; To configure the Enable slow scan log:# # Vim
=============Welcome reprint, please indicate the sourceLi Hui (DBA)Date: 20151008=============1 Installing Percona ToolkitGo to official website to download2. Installing Anemometer: Https://github.com/box/Anemometer3. Download PHP related
In the My.cnf file, add:DataDir =/usr/local/mysql/datalong_query_time = # record the query time checked for 1 seconds. log-slow-queries =/usr/local/mysql/log/db-test2-slow.log# Log directory. #log-queries-not-using-indexes# represents a query that
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.