I've installed MySQL 5.6 on a CentOS 7 server and I'm trying to change the error log location from the default /var/log/mysql.log to /var/log/mysqld.err. MySQL is running properly when I use the default file location, but the systemd service fails with err 13 - Permission Denied when I try to change the logfile location. I made sure to set the file access permissions and owner/group and restart the service with the following:

chown mysql:mysql /var/log/mysqld.err
chmod 640 /var/log/mysqld.err
systemctl daemon-reload
systemctl restart mysql

but the mysqld service still fails with the Permission Denied error when it tries to log output into /var/log/mysqld.err.

I've even tried setting the file access permissions on /var/log/mysqld.err to 777. In this case, the mysqld_safe script was able to write to the logfile successfully when I ran it manually, but the systemd service still fails even though I allowed any user to edit the file.

Are there settings other than file access rights and owner/group settings that limit what files a systemd service can access? As a side note, I have made no modifications to the service script that is installed from the MySQL repo, nor have I added any overwrite files for the service.

  • 1
    Did you check SELinux permissions? If its log is hardcoded in an SELinux rule, you'd have to add an other for your new file. looking at the file /var/log/audit/audit.log for denied entries as well as checking what gives semanage fcontext --list |grep mysql would give some informations about this – A.B Apr 18 '18 at 16:50
  • And a complimentary chcon (before correction) or restorecon (once fixed) could help. chcon -v --reference=/var/log/mysql.log /var/log/mysqld.err – A.B Apr 18 '18 at 16:59
  • @A.B You were right about the SELinux permissions. Thanks for the help. – Copernicus Apr 18 '18 at 17:25

A.B was correct about the problem being with the SELinux permissions. The new file needed a mysqld_log_t type. I fixed the issue by changing the type:

chcon -t mysqld_log_t /var/log/mysqld.err

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.