Getting error while inserting blob datatype value into mysql table

倾然丶 夕夏残阳落幕 提交于 2021-02-05 09:40:52

问题


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 column contains pdf files of fruit. My file mango.pdf in desktop is size of 190 KB.

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


回答1:


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

See https://dev.mysql.com/doc/refman/8.0/en/string-literals.html

Edit : If it still doesn't work :

  • 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 ?


来源:https://stackoverflow.com/questions/57049661/getting-error-while-inserting-blob-datatype-value-into-mysql-table

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