我不明白为什么计算机重启后常规和慢速查询日志是空的。使用 systemctl 重启服务器后,日志会被填充。重启后,创建的文件为空。
$ stat /var/log/mysql/query.log
File: '/var/log/mysql/query.log'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 801h/2049d Inode: 6947352 Links: 1
Access: (0660/-rw-rw----) Uid: ( 89/ mysql) Gid: ( 89/ mysql)
Access: 2016-04-28 05:04:04.530835820 +0200
Modify: 2016-04-28 05:04:04.530835820 +0200
Change: 2016-04-28 05:04:04.530835820 +0200
Birth: -
$ stat /var/log/mysql/slow.log
File: '/var/log/mysql/slow.log'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 801h/2049d Inode: 6947484 Links: 1
Access: (0660/-rw-rw----) Uid: ( 89/ mysql) Gid: ( 89/ mysql)
Access: 2016-04-28 05:04:04.530835820 +0200
Modify: 2016-04-28 05:04:04.530835820 +0200
Change: 2016-04-28 05:04:04.530835820 +0200
Birth: -
我的.cnf:
# The MariaDB server
[mysqld]
port = 3306
socket = /run/mysqld/mysqld.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
character-set-server = utf8
general_log = 1 # log every query
general_log_file = /var/log/mysql/query.log
slow_query_log = 1
long_query_time = 1
Systemd 单元文件:
$ cat /etc/systemd/system/multi-user.target.wants/mysqld.service
[Unit]
Description=MariaDB database server
After=syslog.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/bin/mysqld --pid-file=/run/mysqld/mysqld.pid
ExecStartPost=/usr/bin/mysqld-post
Restart=always
PrivateTmp=true
[Install]
WantedBy=multi-user.target
服务重启后,日志将被填充:
$ sudo systemctl restart mysqld.service
$ stat /var/log/mysql/query.log
File: '/var/log/mysql/query.log'
Size: 255 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 6947352 Links: 1
Access: (0660/-rw-rw----) Uid: ( 89/ mysql) Gid: ( 89/ mysql)
Access: 2016-04-28 05:04:04.530835820 +0200
Modify: 2016-04-28 06:50:52.534122763 +0200
Change: 2016-04-28 06:50:52.534122763 +0200
Birth: -
$ stat /var/log/mysql/slow.log
File: '/var/log/mysql/slow.log'
Size: 171 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 6947484 Links: 1
Access: (0660/-rw-rw----) Uid: ( 89/ mysql) Gid: ( 89/ mysql)
Access: 2016-04-28 05:04:04.530835820 +0200
Modify: 2016-04-28 06:50:51.854122769 +0200
Change: 2016-04-28 06:50:51.854122769 +0200
Birth: -