如何使用LOAD_FILE将文件加载到MySQL Blob中? [英] How to use LOAD_FILE to load a file into a MySQL blob?

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

问题描述

我试图将文件加载到MySQL blob(在Mac上).

I tried to load a file into a MySQL blob (on a Mac).

我的查询是

INSERT INTO MyTable VALUES('7', LOAD_FILE('Dev:MonDoc.odt'))

没有错误出现,但文件未加载到Blob中.

No error appears but the file is not loaded into the blob.

推荐答案

LOAD_FILE(文件名)

LOAD_FILE(file_name)

读取文件并以字符串形式返回文件内容.要使用这个 功能,该文件必须位于服务器主机上,您必须 指定文件的完整路径名,并且您必须具有FILE 特权.该文件必须所有人均可读取,并且其大小应小于 max_allowed_pa​​cket字节.如果secure_file_priv系统变量是 设置为非空目录名称,要加载的文件必须为 位于该目录中.

Reads the file and returns the file contents as a string. To use this function, the file must be located on the server host, you must specify the full path name to the file, and you must have the FILE privilege. The file must be readable by all and its size less than max_allowed_packet bytes. If the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.

如果文件不存在或由于以下原因之一而无法读取 如果不满足上述条件,则该函数返回NULL.

If the file does not exist or cannot be read because one of the preceding conditions is not satisfied, the function returns NULL.

从MySQL 5.0.19开始,character_set_filesystem系统变量 控制以文字形式给出的文件名的解释 字符串.

As of MySQL 5.0.19, the character_set_filesystem system variable controls interpretation of file names that are given as literal strings.

mysql> UPDATE t
            SET blob_col=LOAD_FILE('/tmp/picture')
            WHERE id=1;

从这件事中,我发现有不止一件事可能对您造成影响……

From this, I see more than one thing that could be wrong in your case...

  • 您要走完整的路吗?
  • 权限设置是否正确?
  • 该函数返回什么?空吗?
  • 您是否尝试过使用手册中给出的查询?

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

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