Interview Prep/Linux/Permissions, ownership, SELinux and mounts

AppArmor on Ubuntu blocks MySQL from using a new data directory: `mysqld: Can't create/write to file '/data/mysql/...' (Errcode: 13)`.

IntermediateTroubleshootingPermissions, ownership, SELinux and mounts
Answer

Likely causes → The usr.sbin.mysqld AppArmor profile only allows /var/lib/mysql.

Diagnose →

sudo aa-status | grep mysqld
sudo journalctl -k | grep -i apparmor | grep DENIED

Fix → Add the path to /etc/apparmor.d/local/usr.sbin.mysqld:

/data/mysql/ r,
/data/mysql/** rwk,

Then sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld and restart MySQL. Or bind-mount /data/mysql onto /var/lib/mysql.

Prevent → Use the local/ override files so package updates don't wipe your changes.

All Linux questions Roadmap: Linux

More on Permissions, ownership, SELinux and mounts