MySQL – Fix ‘Can’t Create/Write to File’ Permission Denied Error

mariadbMySQLpermissions

My main volume is a 20GB SSD disk mounted on /. I have a 4TB HDD mounted in /home. So to save space I want to set the mysql temporary directory to /home/mysqltmp.

However when I set to this directory mysql won't start. I get error:

mysqld: Can't create/write to file '/home/mysqltmp/ibm7cVN0' (Errcode: 13 "Permission denied")

I checked the permission and it is correct:

# ls -ld /home/mysqltmp/
drwxrwxrwx 2 mysql mysql 4096 Apr  4 03:19 /home/mysqltmp/

Running mysqld as root it starts without problem.

Server:

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.6 LTS
Release:    16.04
Codename:   xenial

Note: Problem arose after updating to 16.04, was working on 14.04

MySQL details:

# mysql -V
mysql  Ver 15.1 Distrib 10.1.38-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Best Answer

From What to Do if MariaDB Doesn't Start

MariaDB's systemd unit file restricts access to /home, /root, and /run/user by default. This restriction can be removed by setting the ProtectHome option to false for the MariaDB systemd service. For example, you can reconfigure the MariaDB systemd service to allow access to /home by executing the following commands:

tee /etc/systemd/system/mariadb.service.d/dontprotecthome.conf <<EOF
[Service]

ProtectHome=false
EOF
systemctl daemon-reload

ref

After this fix your permission:

chmod go-rw /home/mysqltmp/