I'm having troubles using the LOAD_FILE() function in my environment.

I'm trying to add a file to a BLOB field but whenever I try to insert or update this field with LOAD_FILE(), this field is being set as NULL.

I already checked all common problems which includes system variables, file size and max packet Size and permission problems (Both DB and Linux permissions), even some workaround that included moving the file to a Mysql Owned directory, the problem persists.

Do note that when using LOAD_FILE in a statement similar to

SELECT LOAD_FILE('/foo/bar.jpg');

does work and the file raw data gets displayed, either via CLI or using a DBA tool like DBeaver.

Dump of the table:

CREATE TABLE `table` (
  `string` varchar(3) NOT NULL,
  `blob` blob NOT NULL,
  PRIMARY KEY (`id`),

Each file size I want to insert is around 8kb in size.

I'd appreciate any help with this issue.

1 Answer 1


LOAD_FILE, only reads the contents from the file and returns the contents from itself as a string, you try to add an image into field and using this function isn't gonna be possible. Besides you should have FILE privilege to you could do this and allocating the file into /var/lib/mysql-files. Being this a bad practice, the best is add the route relative or absolute from this file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.