Home > Database > Mysql Tutorial > body text

MySQL命令行开启slow.log失败解决_MySQL

WBOY
Release: 2016-06-01 13:35:51
Original
1123 people have browsed it

bitsCN.com

MySQL命令行开启slow.log失败解决

 

有需要去看下slow.log,但是发现slow.log好久没写了。

看了下服务器设置:

root@(none) 01:13:41>show global variables like '%slow%';

+---------------------+-------------------------+

| Variable_name | Value |

+---------------------+-------------------------+

| log_slow_queries | OFF |

| slow_launch_time | 2 |

| slow_query_log | OFF |

| slow_query_log_file | /u01/mysql/log/slow.log |

+---------------------+-------------------------+

4 rows in set (0.00 sec)

关闭的,于是开启,竟然报错。

root@(none) 01:14:27>set global slow_query_log=1;

ERROR 1146 (42S02): Table 'mysql.slow_log' doesn't exist

发现mysql.slow_log表不存在,desc了下,确实不存在。该表,是当开启参数log_output设置为table的时候,slow.log会记录到这个表里面,但是由于记录该表会对性能有影响,所以一般都是记录到FILE里面,然后再用脚本来处理。

 

那么难道写FILE也必须该表存在吗?

我手动把这个表建上。

// 不让该操作写到binlog中

set session sql_log_bin=0;

use mysql

CREATE TABLE `slow_log` (

`start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

`user_host` mediumtext NOT NULL,

`query_time` time NOT NULL,

`lock_time` time NOT NULL,

`rows_sent` int(11) NOT NULL,

`rows_examined` int(11) NOT NULL,

`db` varchar(512) NOT NULL,

`last_insert_id` int(11) NOT NULL,

`insert_id` int(11) NOT NULL,

`server_id` int(10) unsigned NOT NULL,

`sql_text` mediumtext NOT NULL

) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'

 

然后:

root@mysql 01:34:02>set global slow_query_log=1;

Query OK, 0 rows affected (0.00 sec)

 

设置ok,来测试下:

root@(none) 01:35:40>select sleep(2);

+----------+

| sleep(2) |

+----------+

| 0 |

+----------+

1 row in set (2.00 sec)

 

slow.log里面:

Time: 130124 13:35:52

# User@Host: root[root] @ localhost []

# Query_time: 2.002410 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0

SET timestamp=1359005752;

select sleep(2);

 

设置成功。

总结:

mysql.slow_log表还是必须的,没有这个表slow log 也不能输出到FILE。

 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!