Why does LOAD_FILE returns null?
MySQL Statement:
SELECT LOAD_FILE('/tmp/test.jpg');
According to the MySQl manual, these rules must be followed:
- The file must be located on the server host
- You must specify the full path name to the file
- You must have the FILE privilege
- The file must be readable by the server and its size less than max_allowed_packet bytes
- If the secure_file_priv system variable is set to a nonempty directory name,
the file to be loaded must be located in that directory
Don’t just move the file to /tmp and expect mysql to find it, in our case the the “secure_file_priv” was set to non null value (see below)
The files needed to be saved to “/var/lib/mysql-files”
You can always change this location in you MySQL config file.
Once we moved the file to the location indicated in “secure_file_priv”, we were able to load the files:
Reference
https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_load-file