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.
More on Permissions, ownership, SELinux and mounts
nginx returns 403 and logs `open() "/srv/www/index.html" failed (13: Permission denied)`, even after `chmod -R 777 /srv/www`.IntermediateA script fails with `bash: ./deploy.sh: Permission denied` even though `ls -l` shows `-rwxr-xr-x`.BeginnerA script fails with `/bin/bash^M: bad interpreter: No such file or directory`.BeginnerA user gets `-bash: cd: /srv/project: Permission denied` although they're in the group that owns `/srv/project` (mode `770`).BeginnerApache can't connect to a backend: `AH00957: HTTP: attempt to connect to 127.0.0.1:8080 (localhost) failed` and `ausearch` shows `denied { name_connect }`.IntermediateA service fails to bind to a custom port: `bind() to 0.0.0.0:8888 failed (13: Permission denied)` while running as root.Intermediate