首先,我们通过mysql命令进入mysql命令行中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@yunuo_vm ~]# mysql -u root -p
Enter
password
:
Welcome
to
the MySQL monitor. Commands
end
with
;
or
\g.
Your MySQL
connection
id
is
4977
Server version: 5.6.17 Source distribution
Copyright (c) 2000, 2014, Oracle
and
/
or
its affiliates.
All
rights reserved.
Oracle
is
a registered trademark
of
Oracle Corporation
and
/
or
its
affiliates. Other names may be trademarks
of
their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear the
current
input statement.
mysql>
|
ps:这里的MySQL版本是5.6.17
OK,进入到控制台了,接下来,我们查看下MySQL默认配置中多少秒才算慢查询
1
2
3
4
5
6
7
|
mysql> show variables
like
'long%'
;
+
-----------------+-----------+
| Variable_name | Value |
+
-----------------+-----------+
| long_query_time | 10.000000 |
+
-----------------+-----------+
1 row
in
set
(0.00 sec)
|
如上表显示,系统默认的慢查询时间上限是10秒,下面我们来把它改成1秒(大家也可以根据自己实际情况来定);
1
2
|
mysql>
set
long_query_time=1; 注: 我设置了1, 也就是执行时间超过1秒的都算慢查询。
Query OK, 0
rows
affected (0.00 sec)
|
哦了!最后我们来瞅瞅MySQL开启慢查询日志记录没有;
1
2
3
4
5
6
7
8
|
mysql> show variables
like
'slow%'
;
+
---------------------+---------------+
| Variable_name | Value |
+
---------------------+---------------+
| slow_launch_time | 2 |
| slow_query_log |
OFF
|
| slow_query_log_file | /tmp/slow.log |
+
---------------------+---------------+
|
ps:
slow_query_log //是否打开日志记录
slow_query_log_file //日志存放位置
MySQL默认没有开启慢查询,下面我们来开启下:
1
2
|
mysql>
set
global
slow_query_log=
'ON'
;
Query OK, 0
rows
affected (0.00 sec)
|