如何使用 LOAD_FILE 将文件加载到 MySQL blob 中?

How to use LOAD_FILE to load a file into a MySQL blob?(如何使用 LOAD_FILE 将文件加载到 MySQL blob 中?)

本文介绍了如何使用 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(file_name)

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...

  • 您是否通过了完整路径?
  • 权限设置是否正确?
  • 函数返回什么?NULL?
  • 您是否尝试过使用手册中给出的查询?

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

本文标题为:如何使用 LOAD_FILE 将文件加载到 MySQL blob 中?