SELECT INTO OUTFILE permission denied but the user can write to the directory

This may be caused by mysql user permissions.

As stated here https://dba.stackexchange.com/questions/17029/cannot-output-mysql-data-to-file

To give yourself FILE privilege, do the following:

  1. service mysql restart --skip-networking --skip-grant-tables
  2. mysql <hit enter>
  3. UPDATE mysql.user SET File_priv = 'Y' WHERE user='lea' AND host='localhost';
  4. exit
  5. service mysql restart

The linux user can write a file. But the mysql service may be blocked by apparmor.

Check this file: /etc/apparmor.d/usr.sbin.mysqld.

Add your project folder there:

/usr/sbin/mysqld {
    [...]
    /home/datam/xfers/online/ r,
    /home/datam/xfers/online/* rw
    [...]
}

Finally, do a

sudo /etc/init.d/apparmor reload

On modern systems mariaDB & mysql gets installed with systemd support. Among other things, it has this setting in /etc/systemd/system/mysql.service:

Prevent accessing /home, /root and /run/user

ProtectHome=true

That's what stops it from writing in /home.