How do I use LOAD_FILE to insert value from a file into a table?

2.5k Views Asked by At

I tried to insert a text file into my database, using this code:

INSERT INTO test.table (url_address, html)
VALUES ('abc', LOAD_FILE('C:\Documents and Settings\eran\Desktop\1.txt'));

However, I get null in the html column. How can I get the data from the text file to my database?

1

There are 1 best solutions below

1
On

MySQL LOAD_FILE() reads the file and returns the file contents as a string.

To use this function, the file must be located on the host server, user must specify the full path name of the file, and user must have the FILE privilege. The file must be readable and size must be less than max_allowed_packet (set in the my.ini file) bytes. It returns NULL if the file does not exist or can’t be read.

Try using double back slash "\" for the path. I do not know if it will work.

http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_load-file http://www.w3resource.com/mysql/string-functions/mysql-load_file-function.php