用MYSQL 5.7.9 作為ZABBIX 2.4.7 的監控數據庫. 前段時間開啟了慢查詢日志, 後來發現慢查詢日志膨脹到了700M
查看最後100條 大部分都是 0.1 秒的 後來想改, 以前是動態設置的 set global slow_query_log=1; 方式的 .
然後想直接用配置文件/etc/my.cnf 配慢查詢
7 [mysqld]
8
9 # Remove leading # and set to the amount of RAM for the most important data
10 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
11 innodb_buffer_pool_size = 128M
12
13 # Remove leading # to turn on a very important data integrity option: logging
14 # changes to the binary log between backups.
15 # log_bin
16
17 # These are commonly set, remove the # and set as required.
18 basedir = /LANMP/mysql
19 datadir = /MYSQLDATA/data
20 port = 3306
21 # server_id = .....
22 socket = /tmp/mysql.sock
23
24 # Remove leading # to set options mainly useful for reporting servers.
25 # The server defaults are faster for transactions and fast SELECTs.
26 # Adjust sizes as needed, experiment to find the optimal values.
27 join_buffer_size = 128M
28 sort_buffer_size = 2M
29 read_rnd_buffer_size = 2M
30
31 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
32
33 character_set_server=utf8
34 init_connect='SET NAMES utf8'
35 slow_query_log = 1
36 slow_query_log_file = /MYSQLDATA/mysql_slow_query.log
37 long_query_time = 5
38 log_queries_not_using_indexes = ON
反復啟動了好多次 service mysqld restart
mysql> show variables like '%query%';
+------------------------------+---------------------------------+
| Variable_name | Value |
+------------------------------+---------------------------------+
| binlog_rows_query_log_events | OFF |
| ft_query_expansion_limit | 20 |
| have_query_cache | YES |
| long_query_time | 5.000000 |
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 1048576 |
| query_cache_type | OFF |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
| slow_query_log | ON |
| slow_query_log_file | /MYSQLDATA/mysql_slow_query.log |
+------------------------------+---------------------------------+
13 rows in set (0.00 sec)
老是OFF 狀態 而其他的 LONG_QUERY_TIME 得到了改變 5秒
用動態方式設置 報錯
mysql> set global slow_query_log=1;
ERROR 29 (HY000): File '/MYSQLDATA/mysql_slow_query.log' not found (Errcode: 13 - Permission denied)
對我已經把它給刪了, 為傻不自己創建個?
只好自己touch 一個
還是報錯 ?
ps -ef |grep mysqld 發現 還有個mysql用戶啟動了mysql
看來 是用mysql用戶讀取慢查詢日志的 用戶權限問題啦