views:

24

answers:

2

I know there's the LOAD DATA INFILE statement, which allows me to INSERT structured data into a table.

What I'm curious about, is whether it is possible to INSERT contents of a file into single column. So, is something like this:

INSERT INTO my_table (stamp, what) VALUES (NOW(), LOAD DATA INFILE 'my_file');

possible?

+4  A: 

Yes it's possible. You can use the LOAD_FILE() function:

CREATE TABLE my_table (stamp datetime, what text);

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

You'll have to make sure that the file is readable by MySQL, and that your MySQL user has the FILE privilege. This is the same privilege required for LOAD DATA INFILE.

Daniel Vassallo
Thank you, this is exactly what I need.
Martin Tóth
+1  A: 

edit: I understood you wrong, sorry, Daniel Vassallo has the right answer. May this is useful anyway

I think you are looking for BLOB or TEXT, see docs. If you want to store file date inside the datebase, these are what you are possibly looking for

DrColossos
Is my formulation of question unclear? (i.e. should I modify it?)
Martin Tóth
Nope, after re-reading your question, I understood it perfectly. Was just a little too quick with the answer ;)
DrColossos