Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

MariaDB will not start after a move: Can't create test file ... lower-test

Error[Warning] Can't create test file /home/mysql/beta.lower-test

Short answer

The server writes a small test file in its data directory at startup. If that write is refused, it logs Can't create test file and aborts. The usual reasons are wrong ownership or parent directory permissions, a systemd unit that hides /home, an AppArmor profile that does not know the new path, or SELinux labels.

  • Applies to MariaDB 10.11, MariaDB 11.4, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find the data directory the server really uses, then see who owns it and whether every parent folder can be entered.

    mariadbd --help --verbose | grep 'datadir' | tail -1
    namei -l /home/mysql
  2. 2Match what you see, then jump to its fix

    1. 1Can't create test file ... lower-test, then [ERROR] AbortingWrong owner, or a parent directory that cannot be enteredFix
    2. 2Permission Denied although ownership is right, with the data directory under /homeThe systemd unit hides /home (ProtectHome)Fix
    3. 3Permission denied in the error log and an apparmor denial in the kernel log, on Ubuntu or DebianAppArmor does not know the new data directoryFix
    4. 4avc: denied { write } in /var/log/audit/audit.log, on RHEL-family systemsSELinux gives the new path the wrong labelFix

What does the error look like?

  • [Warning] Can't create test file /home/mysql/beta.lower-test
  • [ERROR] Aborting
  • Permission Denied

Cause 1 of 4

Wrong owner, or a parent directory that cannot be entered

1Check

The whole data directory must belong to the user that runs mariadbd, usually mysql. Its directories need the x bit for the owner, and every parent directory up to / needs x for user, group and other.

ls -ld /home/mysql
namei -l /home/mysql

2Fix

Give the tree back to mysql and open the execute bit on the parents.

sudo chown -R mysql:mysql /home/mysql
sudo chmod 755 /home

3Verify

Start the service.

sudo systemctl start mariadb

Confirmed by mariadb.com

Did this fix it?

Cause 2 of 4

The systemd unit hides /home (ProtectHome)

1Check

The default unit file sets ProtectHome, which blocks access to /home, /root and /run/user. It also sets ProtectSystem=full, which restricts a few other directories.

systemctl show mariadb.service | grep -E 'ProtectHome|ProtectSystem'

2Fix

Add a drop-in that turns ProtectHome off, then reload systemd. For a data directory under /usr/local, grant it with ReadWritePaths instead.

sudo systemctl edit mariadb.service
# in the editor:
[Service]
ProtectHome=false
# then:
sudo systemctl daemon-reload

3Verify

Start the service.

sudo systemctl start mariadb

Confirmed by mariadb.com

Did this fix it?

Cause 3 of 4

AppArmor does not know the new data directory

1Check

Recent Ubuntu and Debian packages ship an AppArmor profile that is on by default. Look for denials.

aa-status | grep mariadb
sudo dmesg | grep -i apparmor

2Fix

Map the old path to the new one in the alias file, then restart AppArmor. Local additions belong in /etc/apparmor.d/local/mariadbd.

# add to /etc/apparmor.d/tunables/alias
alias /var/lib/mysql/ -> /data/mariadb/,
# then:
sudo systemctl restart apparmor

3Verify

Start the service and check for new denials.

sudo systemctl start mariadb
sudo dmesg | grep -i apparmor

Confirmed by mariadb.com

Did this fix it?

Cause 4 of 4

SELinux gives the new path the wrong label

1Check

A custom data directory needs the mysqld_db_t context. Check the current label.

ls --directory --scontext /mariadb/data

2Fix

Add the file context rule for the directory and apply it.

sudo semanage fcontext -a -t mysqld_db_t "/mariadb/data(/.*)?"
sudo restorecon -Rv /mariadb/data

3Verify

Start the service.

sudo systemctl start mariadb

Confirmed by mariadb.com

Did this fix it?

How do I stop it coming back?

  • After moving a data directory, check owner, parent permissions, the systemd unit and the security profile before the first start.
  • Keep the data directory outside /home when you can.
  • Do not turn AppArmor or SELinux off to hide the problem; add the path rule instead.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.