MySql开启慢查询报错:Could not open /var/log/slow_query.log for logging (error 13).

Turning logging off for the whole duration of the MySQL server process.

File '/var/log/slow_query.log' not found (Errcode: 13 - Permission denied)
[ERROR] Could not open /var/log/slow_query.log for logging (error 13). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
File '/var/log/query.log' not found (Errcode: 13 - Permission denied)

 
在配置慢查询的时候,指定的文件一直没出现,查看了mysql日志发现这个问题;
经过一阵网上搜索,没有收获;
认真看了错误信息,原来是文件权限不够。
解决:
1、使用root用户登录,在指定的文件夹下新建文件,如:
cd /var/log
touch slow_query.log
touch query.log
2、对新建的文件进行更改
chown mysql slow_query.log
chown mysql query.log
3、重启mysql:service mysql restart


登录mysql进行测试
select sleep(6);

现在指定文件中
select sleep(6);
# Time: 160517 16:52:15
# User@Host: root[root] @ localhost [127.0.0.1]  Id:     5
# Query_time: 3.313177  Lock_time: 0.000292 Rows_sent: 843  Rows_examined: 1015609

成功了!!!

原文地址:https://www.cnblogs.com/hcrs/p/5502433.html