mysql 开启慢查询 如何打开mysql的慢查询日志记录
mysql慢查询日志对于跟踪有问题的查询非常有用,可以分析出当前程序里有很耗费资源的sql语句,那如何打开mysql的慢查询日志记录呢,接下来将详细为您介绍
mysql慢查询日志对于跟踪有问题的查询非常有用,可以分析出当前程序里有很耗费资源的sql语句,那如何打开mysql的慢查询日志记录呢?其实打开mysql的慢查询日志很简单,只需要在mysql的配置文件里(windows系统是my.ini,linux系统是my.cnf)的[mysqld]下面加上如下代码:
代码如下:
log-slow-queries=/var/lib/mysql/slowquery.log
long_query_time=2
注:
log-slow-queries 设置把日志写在那里,为空的时候,系统会给慢查询日志赋予主机名,并被附加slow.log. /var/lib/mysql/slowquery.log为日志存放的文件的位置,一般这个目录要有mysql的运行帐号的可写权限,一般都将这个目录设置为mysql的数据存放目录
long_query_time=2中的2表示查询超过两秒才记录.
如果设置了参数log-long-format,那么所有没有使用索引的查询也将被记录。在文件my.cnf或my.ini中加入下面这一行可以记录这些查询
这是一个有用的日志。它对于性能的影响不大(假设所有查询都很快),并且强调了那些最需要注意的查询(丢失了索引或索引没有得到最佳应用)
# Time: 070927 8:08:52
# User@Host: root[root] @ [192.168.0.20]
# Query_time: 372 Lock_time: 136 Rows_sent: 152 Rows_examined: 263630
select id, name from manager where id in (66,10135);
这是慢查询日志中的一条,用了372秒,锁了136秒,返回152行,一共查了263630行
如果日志内容很多,用眼睛一条一条去看会累死,mysql自带了分析的工具,使用方法如下:
命令行下,进入mysql/bin目录,输入mysqldumpslow –help或--help可以看到这个工具的参数,主要有
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
Parse and summarize the MySQL slow query log. Options are
--verbose verbose
--debug debug
--help write this text to standard output
-v verbose
-d debug
-s ORDER what to sort by (t, at, l, al, r, ar etc), 'at' is default
-r reverse the sort order (largest last instead of first)
-t NUM just show the top n queries
-a don't abstract all numbers to N and strings to 'S'
-n NUM abstract numbers with at least n digits within names
-g PATTERN grep: only consider stmts that include this string
-h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard),
default is '*', i.e. match all
-i NAME name of server instance (if using mysql.server startup scrīpt)
-l don't subtract lock time from total time
-s,是order的顺序,说明写的不够详细,俺用下来,包括看了代码,主要有
c,t,l,r和ac,at,al,ar,分别是按照query次数,时间,lock的时间和返回的记录数来排序,前面加了a的时倒叙
-t,是top n的意思,即为返回前面多少条的数据
-g,后边可以写一个正则匹配模式,大小写不敏感的
mysqldumpslow -s c -t 20 host-slow.log
mysqldumpslow -s r -t 20 host-slow.log
上述命令可以看出访问次数最多的20个sql语句和返回记录集最多的20个sql。
mysqldumpslow -t 10 -s t -g “left join” host-slow.log
这个是按照时间返回前10条里面含有左连接的sql语句。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



Like win10, win11 has introduced the memory integrity function to protect the system, but many friends don’t know what this function is used for. So, should win11 memory integrity be turned on? In fact, this has something to do with the computer system. Should memory integrity be turned on in win11: Answer: If the computer configuration is high, or it is just for daily office audio and video, it can be turned on; if our computer configuration is poor, or we are pursuing high performance, we should not turn it on. Introduction to win11 memory integrity: 1. The principle of memory integrity is that hardware virtualization creates an isolated environment. 2. It protects our system and memory security. 3. The disadvantage is that after turning on this function, it will run at any time, occupying memory and reducing performance. 4. And once it is turned on, it will be more troublesome to turn it off. It will definitely

There is a dlss function in NVIDIA. After users turn on dlss, the game frame rate can be greatly improved. Therefore, many friends are asking the editor how to turn on dlss. First, make sure that the graphics card supports dlss and the game supports dlss, then you can enable it in the game. Let’s take a look at the specific tutorials below. Answer: DLSS generally needs to be opened in the game. To enable dlss, you must meet the conditions of the device and game. dlss is the "ray tracing effect", you can enter the game settings. Then go to the "Image or Graphics" settings. Then find "Ray Tracing Lighting" and click to open it. d

If you want to open vbs after closing it before, you can also open it. We can use the command code to open it. Let's take a look at how to open vbs. It is actually very simple. How to open win11vbs: 1. First, we click on the “Start Menu”. 2. Then click "Windows Terminal". 3. Then enter "bcdedit/sethypervisorlaunchtypeauto". 4. Then restart the computer, open the start menu, and search for "system information" in the search bar. 5. Then check whether "virtualization-based security" is turned on.

Is it necessary to enable hardware accelerated GPU? With the continuous development and advancement of technology, GPU (Graphics Processing Unit), as the core component of computer graphics processing, plays a vital role. However, some users may have questions about whether hardware acceleration needs to be turned on. This article will discuss the necessity of hardware acceleration for GPU and the impact of turning on hardware acceleration on computer performance and user experience. First, we need to understand how hardware-accelerated GPUs work. GPU is a specialized

How to enable vt virtualization in Win7? Some users use mobile phone emulators on their computers, but when running the software, they are prompted that our computers do not have the vt virtualization function turned on. So how do we enable this function on the motherboard? Many friends don’t know how to operate it in detail. The editor has compiled a tutorial on how to enable the vt virtualization function on the motherboard in win7 system. If you are interested, follow the editor and read on. ! Tutorial on how to enable vt virtualization function on the motherboard in win7 system 1. First, we restart the computer and use hotkeys to enter the bios settings. 2. Click AdvancedMode in the lower right corner. 3. Select CPU settings in the advanced options. 4. Then find the VT below

Friends who use win10 system often ask how to enable Ethernet disabling. In fact, this operation is very simple. You need to enter the network settings to perform it. Next, I will take you to take a look. How to disable Ethernet in win10: 1. First, click the network connection icon in the lower right corner to open the network and Internet settings. 2. Then click on Ethernet. 3. Then click "Change Adapter Options". 4. At this point, you can right-click "Ethernet" and select Disable.

In the win10 system, many users will video chat with good friends or family, or use the camera function when taking photos. However, some win10 system users find that the computer cannot open the camera and prompts that there is no permission, so video chat cannot be done. How to deal with it? Let’s take a look at the specific solutions with the editor. 1. First check whether the camera permission is turned on. The "win+i" shortcut key opens the settings window. At this time we can see the camera under Privacy, click on it. 2. Find the camera in the left column. On the right, we can see that the access permission for the camera of this device has been turned off. Click Change. 3. Select Turn on, and then you can turn on the camera. The above is the detailed operation of opening computer camera permissions in win10.

Recently, a friend found that the computer microphone cannot be turned on. Nowadays, both desktop computers and laptops have a microphone function. This also provides us with great convenience. However, many friends suddenly have microphones turned on during use. I found that my computer microphone has no sound. The editor below will teach you how to solve the problem by turning on the computer microphone. Let’s take a look at the details together. Methods for turning on the microphone permission in Windows 10: 1. When turning on the recorder under Windows 10, the prompt "You need to set the microphone in settings" pops up. 2. At this time, we can click the start button in the lower left corner of the screen and select the "Settings" menu item in the pop-up menu. 3. Click the "Privacy" icon in the Windows Settings window that opens. 4
