5

When starting mysql on Centos servers with a custom data directory you might get an error similar to the following:

2014-10-15 10:23:56 17081 [Warning] Can't create test file /database/mysql/localhost.lower-test
Haluk
  • 599
  • 3
  • 10
  • 22

3 Answers3

4

If you tried fixing ownership and permissions.

chown -R mysql:mysql /new-path/mysql
chmod 0755 /new-path/mysql

And you do not have SELinux enabled but you still have a problem. All you need to do is to edit /usr/lib/systemd/system/mariadb.service

ProtectSystem=full
ProtectHome=true

and undefine those variables (setting it to false won't work)

ProtectSystem=
ProtectHome=

And reload daemon

systemctl daemon-reload

After I did this it finally worked. Interesting is that this occurs only with MariaDB 10.1 Those variables are not existent for earlier versions. Recently I have found this bug:

https://jira.mariadb.org/browse/MDEV-13896

EDIT:

Since this configuration gets overwritten after a MariaDB update, I have found a permanent fix to avoid any further downtime because of this.

cp /usr/lib/systemd/system/mariadb.service /etc/systemd/system/mariadb.service

Then I made changes here instead

vi /etc/systemd/system/mariadb.service

That's it :)

Luka
  • 191
  • 9
4

If your chmod and chown settings are already correct you might need to look into selinux.
This page explains how to configure selinux for mysql: https://blogs.oracle.com/jsmyth/entry/selinux_and_mysql

Haluk
  • 599
  • 3
  • 10
  • 22
  • And what if selinux is disabled and this still happens? – Luka Mar 07 '18 at 23:54
  • If selinux is disabled. Then you need to check your chmod/chown settings. Another thing you can check is if your harddrive is full. Also check out Uwe's answer above. It could be helpful in your case. – Haluk Mar 08 '18 at 12:48
  • None of the above. The new MariaDB 10.1 adds some weird protection to Systemd service file. I'm gonna write a FIX i discovered as an answer. – Luka Mar 08 '18 at 13:16
2

When running on CentOS 7, check out the systemd unit files which may prevent writing to / protect non-MySQL directories like /home.

The unit files lives in /usr/lib/systemd/system/mariadb.service.

Andriy M
  • 20,973
  • 6
  • 52
  • 93
Uwe
  • 21
  • 2