Mysql Load_File Returns Null

Why does LOAD_FILE returns null?

MySQL Statement:

SELECT LOAD_FILE('/tmp/test.jpg');

According to the MySQl manual, these rules must be followed:

  1. The file must be located on the server host
  2. You must specify the full path name to the file
  3. You must have the FILE privilege
  4. The file must be readable by the server and its size less than max_allowed_packet bytes
  5. 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)
load_file_returns_null

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:
load_file_returns_null2

Reference
https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_load-file

Let's share thisShare on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Leave a Reply


*