Tom
Tom

Reputation: 771

Getting error while inserting blob datatype value into mysql table

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

Upvotes: 0

Views: 1007

Answers (1)

Mark Willis
Mark Willis

Reputation: 848

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 ?

Upvotes: 1

Related Questions