Click to See Complete Forum and Search --> : Inserting from file into table


mizipzor
10-16-2007, 03:10 PM
Im writing a small blog system, using:
mysql Ver 14.12 Distrib 5.0.26, for pc-linux-gnu (i686) using readline 5.2

What I want to do is this; when I write the blogs I write them in a text editor, because its easy. I then save them to a textfile. It is this file I want to insert into the database.

The file could look something like this:

lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum

And from within mysql I want to do something like this:

mysql> insert into blog (title, content) values ("foo", content_of("foo.txt"));

Is there such a command? Otherwise, the sql query would by veeery long if I am to type the entire blog in the query. But maybe that is the way it works, I dont know as Im quite new to databases.

If there isnt such a command, could this be solved by a bash script or something similiar?