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

↘锁芯ラ 提交于 2019-12-12 01:44:32

问题


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:


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



来源:https://stackoverflow.com/questions/14892219/how-do-i-use-load-file-to-insert-value-from-a-file-into-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!