Centos

由於權限,MySQL 日誌無法正常工作

  • November 5, 2015

我在 MariaDB (MySQL) 日誌文件中遇到權限問題。我已經設置了日誌文件,/var/log/mysql但是每當我重新啟動 MariaDB 伺服器時,我都可以看到以下登錄消息/var/log/mysql/mysql_error.log

151104 20:54:53 [ERROR] mysqld: File '/var/log/mysql/mysql_slow.log' not found (Errcode: 13)
151104 20:54:53 [ERROR] Could not use /var/log/mysql/mysql_slow.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.
151104 20:54:53 [ERROR] mysqld: File '/var/log/mysql/mysql_query.log' not found (Errcode: 13)
151104 20:54:53 [ERROR] Could not use /var/log/mysql/mysql_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.

我嘗試將/var/log/mysql遞歸(-R)權限設置為mysql:root,但它們都不起作用,mysql:mysql而且root:root我一直收到相同的消息。我確實檢查了目前的權限/var/log/mysql並閱讀為:

# ls -l mysql/
total 40
-rw-r--r-- 1 mysql root 33088 Nov  4 21:04 mysql_error.log
-rw-r--r-- 1 mysql root     0 Aug  2 16:58 mysql_query.log
-rw-r--r-- 1 mysql root     0 Aug  2 16:58 mysql_slow.log

我正在使用mysql Ver 15.1 Distrib 5.5.46-MariaDB,用於 Linux (x86_64),使用 readline 5.1

這裡有什麼問題?在這種情況下,哪些是正確的權限?

更新

以下是 和 的/var/log權限/var/log/mysql

# ls -lhd /var/log/
drwx------ 12 root root 4.0K Nov  4 20:52 /var/log/
# ls -lhd /var/log/mysql
drwxr-xr-x 2 mysql root 4.0K Nov  4 20:52 /var/log/mysql

我相信您必須先授予 mysql 使用者讀取和執行權限/var/log才能訪問/var/log/mysql. 我剛剛在 RHEL7.1 上對此進行了測試並確認了同樣的問題。

這正是@prem 在評論中建議的那樣。

引用自:https://unix.stackexchange.com/questions/240904