mysql慢查询日志开启和存储格式_MySQL
mysql版本是mysql5.6.22,安装环境windows7。
1.使用该查询日志可以找到有效率问题的sql语句,并记录下来,进行监控。
可以使用如下语句查询和设置慢查询日志
(1) 查看慢查询日志是否开启SHOW VARIABLES LIKE '%show_query_log%'; 或是 SHOW VARIABLES LIKE '%show_query_log%'\G (mysql命令行中使用)
查询结果如下
Variable_name: slow_query_log
Value: OFF
上边Value表示未开启
Variable_name: slow_query_log_file
Value: D:\ProgramFiles\MySQL5.6.22\mysql_master\data\LHY-slow.log
上边Value表示日志存放的路径
set global slow_query_log = on;
(2) 查看未使用索引的查询日志是否开启SHOW VARIABLES LIKE '%log_queries_not_using_indexes%'; 或是 SHOW VARIABLES LIKE '%log_queries_not_using_indexes%'\G (mysql命令行中使用)
查询结果如下
Variable_name: log_queries_not_using_indexes
Value: OFF
上边Value表示未开启
set global log_queries_not_using_indexes = on;
(3) 查看超过设定时间的查询日志SHOW VARIABLES LIKE '%long_query_time%'; 或是 SHOW VARIABLES LIKE '%long_query_time%'\G (mysql命令行中使用)
查询结果如下:
Variable_name: long_query_time
Value: 10.000000
上边value:10s表示记录执行时间超过10秒的sql
set global long_query_time = 1;
exit;
注意1:修改执行之间之后要退出重新登录才会起作用.注意2:设置时间过短导致日志记录过多会很快将磁盘空间沾满,所以应该定期执行磁盘清理,这里设置为1是为了查看执行效果,生产环境中需要自己设置.
以上三个步骤执行完成之后,从数据库中执行任何sql语句就都会被记录到日志中,可以到第一步中那个日志查看日志信息.
以上设置是在控制台处理的,当数据库重启之后,该设置即失效;
长期有效的方式是在mysql安装目录下找到my.ini文件,若是没有该文件,只有mysql-default.ini文件
那么就将该文件备份,然后改名为mysql.ini,然后在该文件中[mysqld]下边添加如下的配置信息即可。
slow_query_log=on
slow_query_log_file=D:/ProgramFiles/MySQL5.6.22/mysql_master/data/LHY-slow.log
log_queries_not_using_indexes=on
long_query_time=1
2.存储格式
# Time: 150401 11:24:27
# User@Host: root[root] @ localhost [127.0.0.1] Id: 7
# Query_time: 0.034002 Lock_time: 0.000000 Rows_sent: 3 Rows_examined: 3
use libu;
SET timestamp=1427858667;
select * from aaa;
分析如下:
(1) Time: 执行时间
(2) User@Host: 执行sql的主机信息
(3) Query_time: sql的执行信息,Lock_time: 锁定时间, Rows_sent: 发送(结果)行数, Rows_examined:扫描的行数
(4) timestamp: 执行时间
(5) select * from aaa; : 查询语句内容
3.慢查询日志分析工具
5种工具: mysqldumpslow,mysqlsla,myprofi,mysql-explain-slow-log,mysqllogfilter
mysqldumpslow mysql自带的分析工具
致歉:本人目前还未找到这些工具在window上使用的方式,若是哪位大神有相关的教程,请@我,谢谢!!!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The logs of win10 can help users understand the system usage in detail. Many users must have encountered log 6013 when looking for their own management logs. So what does this code mean? Let’s introduce it below. What is win10 log 6013: 1. This is a normal log. The information in this log does not mean that your computer has been restarted, but it indicates how long the system has been running since the last startup. This log will appear once every day at 12 o'clock sharp. How to check how long the system has been running? You can enter systeminfo in cmd. There is one line in it.

QQ email: QQ number@qq.com, English QQ email: English or numbers@qq.com, foxmail email account: set up your own account@foxmail.com, mobile phone email account: mobile phone number@qq.com. Tutorial Applicable Model: iPhone13 System: IOS15.3 Version: QQ Mailbox 6.3.3 Analysis 1QQ mailbox has four formats, commonly used QQ mailbox: QQ number@qq.com, English QQ mailbox: English or numbers@qq.com, foxmail Email account: set up your own account@foxmail.com, mobile phone email account: mobile phone number@qq.com. Supplement: What is qq mailbox? 1 The earliest QQ mailbox was only between QQ users

In iOS 17 and macOS Sonoma, Apple has added new formatting options for Apple Notes, including block quotes and a new Monostyle style. Here's how to use them. With additional formatting options in Apple Notes, you can now add block quotes to your notes. The block quote format makes it easy to visually offset sections of writing using the quote bar to the left of the text. Just tap/click the "Aa" format button and select the block quote option before typing or when you are on the line you want to convert to a block quote. This option applies to all text types, style options, and lists, including checklists. In the same Format menu you can find the new Single Style option. This is a revision of the previous "equal-width"

The logs of win10 can help users understand the system usage in detail. Many users must have seen a lot of error logs when looking for their own management logs. So how to solve them? Let’s take a look below. . How to solve win10 log event 7034: 1. Click "Start" to open "Control Panel" 2. Find "Administrative Tools" 3. Click "Services" 4. Find HDZBCommServiceForV2.0, right-click "Stop Service" and change it to "Manual Start "

With the rapid development of the Internet and Web applications, log management is becoming more and more important. When developing web applications, how to find and locate problems is a very critical issue. A logging system is a very effective tool that can help us achieve these tasks. ThinkPHP6 provides a powerful logging system that can help application developers better manage and track events that occur in applications. This article will introduce how to use the logging system in ThinkPHP6 and how to utilize the logging system

iPhone lets you add medications to the Health app to track and manage the medications, vitamins and supplements you take every day. You can then log medications you've taken or skipped when you receive a notification on your device. After you log your medications, you can see how often you took or skipped them to help you track your health. In this post, we will guide you to view the log history of selected medications in the Health app on iPhone. A short guide on how to view your medication log history in the Health App: Go to the Health App>Browse>Medications>Medications>Select a Medication>Options&a

In Linux systems, you can use the following command to view the contents of the log file: tail command: The tail command is used to display the content at the end of the log file. It is a common command to view the latest log information. tail [option] [file name] Commonly used options include: -n: Specify the number of lines to be displayed, the default is 10 lines. -f: Monitor the file content in real time and automatically display the new content when the file is updated. Example: tail-n20logfile.txt#Display the last 20 lines of the logfile.txt file tail-flogfile.txt#Monitor the updated content of the logfile.txt file in real time head command: The head command is used to display the beginning of the log file

When writing web applications, you often need to verify phone numbers. A common method in PHP is to use regular expressions to determine whether the phone number is in the correct format. Regular expressions are a powerful tool that can help you identify certain patterns in concise statements. Below is an example of using regular expressions in PHP to validate phone number format. First, let's define the common format for phone numbers. Phone numbers can contain numbers, parentheses, hyphens, and spaces. A standard phone number should contain 10 digits, preceded by
