Bug #65120 LOAD_FILE won't read files in /tmp
Submitted: 26 Apr 2012 18:00 Modified: 27 Apr 2012 3:35
Reporter: Doug Campbell Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.5.22 OS:Linux
Assigned to: CPU Architecture:Any

[26 Apr 2012 18:00] Doug Campbell
Description:
Using LOAD_FILE to read file into MySQL.  When file is read from /tmp directory, result is always NULL.

How to repeat:
Fedora 16
SELinux Disabled
Using root mysql user

File permissions for /tmp

drwxrwxrwt 15 root root 4096 Apr 27 01:18 /tmp

File permissions for test.htm file

-rwxrwxrwx 1 mysql root 2607540 Apr 26 23:40 /tmp/test.htm

mysql> SELECT LOAD_FILE('/tmp/test.htm');

If I create a new directory /temp with the exact same permissions and place test.htm within it and attempt my test again using /temp/test.htm, LOAD_FILE will work as expected.
[26 Apr 2012 18:08] Sveta Smirnova
Thank you for the report.

I can not repeat described behavior:

mysql> select load_file('/tmp/bar');
+-----------------------+
| load_file('/tmp/bar') |
+-----------------------+
| foo
                  |
+-----------------------+
1 row in set (0.00 sec)

mysql> \! df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda3            126388036  90910968  29056896  76% /
tmpfs                  3968960       720   3968240   1% /dev/shm
...

mysql> select load_file('/dev/shm/bar');
+---------------------------+
| load_file('/dev/shm/bar') |
+---------------------------+
| foo
                      |
+---------------------------+
1 row in set (0.00 sec)

Please provide output of df command.
[26 Apr 2012 18:44] Doug Campbell
Okay.  After much testing, I discovered that this issue is caused by Fedora using something called PrivateTmp.  If I alter the systemd mysqld.service file and comment out the line that has PrivateTmp=true then LOAD_FILE works as expected in /tmp.

So, I am not sure if this is a bug or not.  It is confusing though.
[26 Apr 2012 20:13] Sveta Smirnova
Thank you for the feedback.

This is permission issue, not MySQL bug.
[27 Apr 2012 3:35] Doug Campbell
I wouldn't say it is a permissions issue.  I don't fully understand the use of PrivateTmp namespaces but it seems the issue stems from the fact that MySQL is treating /tmp as a different location than most services running on the system.

Anyway, I agree with you, as I think about it more and more that this is not a bug in MySQL.

Thanks!