90 HAQ
90 HAQ

Reputation: 11

How to add an image into a table of database on workbench?

I'm trying to insert an image in database table but it gives error every time:

Column image cannot be null

Whereas the data type of image column is not null as you can see clearly.

How can I solve this problem?

Execution inside MySQL Workbench:

enter image description here

Upvotes: 1

Views: 367

Answers (1)

Martin Osusky
Martin Osusky

Reputation: 845

MySQL LOAD_FILE function is several conditions to be met to be executed successfully.

  • File which you are trying to load must be present in the same host where MySQL server is running. For example, if your MySQL server is installed on example.com, file must be present on example.com only.
  • Full path name of the file must be specified. So, if your file is located within a user's home directory, assuming username w3r, you must specify '/home/w3r/somefile.txt'
  • User who is executing the command must have FILE privilege. You may grant FILE privilege to a user with following "GRANT FILE on dbname.* TO user@localhost".
  • File in question must be readable by all. If you are trying to load a file which is not present on the users home directory hieararchy, make sure you have read permission on the file.
  • MySQL Server has a max_allowed_packet variable. File in question must not exceed value specified in that variable. You may check value of max_allowed_packet with 'show variables like '%max_allowed_packet%';'; you must have MySQL root privilege for executing this command. You change the value of max_allowed_packet in your MySQL configuration file. Open your my.ini or my.cnf file, find the line max_allowed_packet=some_value and change the value to your desired one, for example if you want to set the valle to say 50MB, write 50MB.
  • MySQL has a secure_file_priv variable. If value of that variable is set to a nonempty directory name, the file to be loaded must be located in that directory. You may find the secure_file_priv variable and its value and may chnage it in your MySQL configuration file.

Upvotes: 1

Related Questions