I tried to load a file into a MySQL blob (on a Mac).
My query is
INSERT INTO MyTable VALUES('7', LOAD_FILE('Dev:MonDoc.odt'))
No error appears but the file is not loaded into the blob.
I tried to load a file into a MySQL blob (on a Mac).
My query is
INSERT INTO MyTable VALUES('7', LOAD_FILE('Dev:MonDoc.odt'))
No error appears but the file is not loaded into the blob.
The manual states the following:
From this, I see more than one thing that could be wrong in your case...
double escape the slahes in the full path if you're in windows.
I just wanted to add one more caveat that I found in my testing:
when using
select load_file('/path/to/theFile.txt');
The file that you are loading HAS to be on the machine the sql instance is running on.This bit me in the butt for a long time because I use MySQL workbench to load files all the time into our various sql instances and when using commands like
LOAD DATA LOCAL INFILE 'C:/path/to/theFile.csv' INTO TABLE
those would easily grab the file off of my local hard drive and process it into the tables regardless of where the actual sql instance was running. However theload_file
command doesn't seem to behave at least for me in the same way (Maybe there exists a local_load_file() command I don't know about). MySQL seems to only allow it to look for files from the local system where the sql instance is running.So if you're like me and you can't figure out why load_file is always returning NULL have no fear...upload the files to the sql server instance and then use that path from your Query browser and all will be well.
I had the same problem with Linux ...
Eventually i could load the file successfully after user and group ownership were changed to 'mysql':
Thanks.
The user that is running mysql, needs to OWN the file. My mistake was, I thought it just needed to be able to READ or EXECUTE the file.