Upload image directly through mySQL Command Line

BurninatorDor picture BurninatorDor · Dec 9, 2011 · Viewed 49.8k times · Source

I have a certain table in mySQL which has a field called "image" with a datatype of "BLOB". I was wondering if it is possible to upload an image in that field directly from the Command Line Client rather than doing it through php...If it is possible, then where exactly should I place my image files?

Answer

Bill Karwin picture Bill Karwin · Dec 9, 2011

Try using the LOAD_FILE() function.

UPDATE `certain_table`
SET image = LOAD_FILE('/full/path/to/new/image.jpg')
WHERE id = 1234;

See the manual for requirements about the path to the filename, privileges, etc.