Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert file into mysql Blob

Tags:

mysql

I try to insert a Open Office document on a blob field. To do this I try

INSERT INTO my_table (stamp, docFile) VALUES (NOW(), LOAD_FILE('/tmp/my_file.odt'));

This works well on windows but on Mac Os the file isn't load on docFile field.

Is anyone has experience about that?

Thanks

like image 334
Flex60460 Avatar asked Feb 02 '12 08:02

Flex60460


1 Answers

File.separator is either / or \ that is used to split up the path to a specific file. For example on Windows it is \ or C:\Documents\Test. But on Mac it is /.

So use File.separator instead of / or \, then it will work for both Mac and Windows.

You can Update the column value having type 'blob'

UPDATE `TableName` SET `ColumnName`=LOAD_FILE('FilePath/FileName.bin') WHERE `YourCondition` 
// FilePath -> C:/foldername/filename.bin
like image 125
srikanthvarma Avatar answered Oct 19 '22 16:10

srikanthvarma