将Blob数据类型值插入mysql表时出现错误 [英] Getting error while inserting blob datatype value into mysql table

查看:52
本文介绍了将Blob数据类型值插入mysql表时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据输入到mysql表Fruitbox中.但是在输入数据时出现错误 Fruitpdf不能为空.我创建了水果盒表,如下所示:

I am trying to enter data into mysql table Fruitbox .But while entering data I am getting error Fruitpdf cannot be null. I created fruitbox table as follows:

Fruitname(varchar(100), Fruitpdf(blob), Fruitprice(int)

Fruitpdf列包含水果的pdf文件.我在桌面上的文件mango.pdf大小为190 KB.

Fruitpdf column contains pdf files of fruit. My file mango.pdf in desktop is size of 190 KB.

我写了以下查询,但是在执行sql语句时出现错误" Fruitpdf不能为空".

I wrote following query but getting error "Fruitpdf cannot be null" while executing sql statement.

INSERT INTO Fruitbox (Fruitname, Fruitpdf, Fruitprice) VALUES ('Mango', LOAD_FILE('C:\Users\Tom\Desktop\mango.pdf'), '100');

我哪里错了?任何帮助深表感谢.谢谢你

Where I am wrong ? Any help is much appreciated. Thanking you

推荐答案

MySQL将字符串中的反斜杠视为转义字符.您需要使用双反斜杠:

MySQL treats a backslash in a string as an escape character. You need to use a double backslash :

LOAD_FILE('C:\\ Users \\ Tom \\ Desktop \\ mango.pdf')

LOAD_FILE('C:\\Users\\Tom\\Desktop\\mango.pdf')

请参见 https://dev.mysql.com/doc/refman/8.0/zh-CN/string-literals.html

如果仍然无法使用:

  • 该文件在MySQL服务器上吗?
  • 是否设置了"secure_file_priv"变量?(喜欢显示变量'secure_file_priv'; )如果是这样,则需要将文件放置在该目录.
  • 您的用户是否具有FILE特权?
  • Is the file on the MySQL server ?
  • Is the 'secure_file_priv' variable set ? (SHOW VARIABLES LIKE 'secure_file_priv';) If so, you will need to place the file under that directory.
  • Does your user have the FILE privilege ?

这篇关于将Blob数据类型值插入mysql表时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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