如何使用 LOAD_FILE 将文件中的值插入到表中? [英] How do I use LOAD_FILE to insert value from a file into a table?

查看:41
本文介绍了如何使用 LOAD_FILE 将文件中的值插入到表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下代码将文本文件插入到我的数据库中:

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'));

但是,我在 html 列中得到 null.如何将文本文件中的数据获取到我的数据库中?

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

推荐答案

MySQL LOAD_FILE() 读取文件并以字符串形式返回文件内容.

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

要使用此功能,文件必须位于主机服务器上,用户必须指定文件的完整路径名,并且用户必须具有 FILE 权限.该文件必须可读且大小必须小于 max_allowed_pa​​cket(在 my.ini 文件中设置)字节.如果文件不存在或无法读取,则返回 NULL.

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-filehttp://www.w3resource.com/mysql/string-functions/mysql-load_file-function.php

这篇关于如何使用 LOAD_FILE 将文件中的值插入到表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆