版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yanerhao/article/details/81505603
方法:https://jingyan.baidu.com/article/454316ab07e522f7a7c03a2c.html
设置慢查询日志存放的位置
set global slow_query_log_file='/var/lib/mysql/test-10-226-slow.log';
报错:
ERROR 1231 (42000): Variable 'slow_query_log_file' can't be set to the value of '/data/users/。。。
设置slow_query_log_file时,目录必须存在,并且mysql 有权读写该目录,
mkdir /var/log/mysql
sudo chown mysql:mysql -R /var/log/mysql
绝大多数的mysql在启动的时候都要加载一个配置文件,
Linux机器下常用的配置文件路径
文件名 | 作用 |
---|---|
/etc/my.cnf |
Global options |
/etc/mysql/my.cnf |
Global options (as of MySQL 5.1.15) |
|
Global options |
$MYSQL_HOME/my.cnf |
Server-specific options |
defaults-extra-file |
The file specified with--defaults-extra-file= |
~/my.cnf |
User-specific options |
-
上面的方法只是临时生效,mysql重启后就会失效
-
编辑配置文件/etc/my.cnf加入如下内容
[mysqld]
slow_query_log = ON
slow_query_log_file = /var/lib/mysql/test-10-226-slow.log
long_query_time = 1
-
修改配置后重启mysql
-
sudo /etc/init.d/mysql restart