0

I have a MYSQL database with a column named img of BLOB type.

When I insert a value into that column like this :

LOAD_FILE('C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Sunset.jpg') 

it works !

But like this :

LOAD_FILE('C:/Documents and Settings/Administrator/My Documents/My Pictures/picture.jpg')

it doesn't work and it tells me that the column img cannot be null !

And in both cases the file exists, and I'm connecting to the database as the root user (all privileges), so I don't understand why I'm getting this error.

Thanks in advance

4
  • 2
    Are you running your database server (mysqld) in elevated permissions? Needs to be run as administrator (from an administrator command prompt, or administrator account if a service) in modern Windows versions to access files in the Administrator folder. Commented May 10, 2014 at 0:17
  • I'm logging as the user "Administrator" in Windows ! Commented May 10, 2014 at 0:28
  • Windows has UAC (user access control). It doesn't allow certain things to happen without elevated privileges, even when you're logged in as administrator. You need to run mysqld in either an administrator command prompt (right click on the command prompt icon and choose run as administrator) or as an administrator service. Commented May 10, 2014 at 0:33
  • OK, Can you please tell me explicitly how to do so ? Commented May 10, 2014 at 0:51

3 Answers 3

1

Maybe problem with max_allowed_packet

1.jpg is a small picture and 2.jpg is a big picture

mysql> DESCRIBE  blob_files;
+-------+---------+------+-----+---------+----------------+
| Field | Type    | Null | Key | Default | Extra          |
+-------+---------+------+-----+---------+----------------+
| id    | int(11) | NO   | PRI | NULL    | auto_increment |
| file  | blob    | YES  |     | NULL    |                |
+-------+---------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

mysql> INSERT INTO blob_files(file) VALUE(LOAD_FILE('D:/2.jpg'));
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> SHOW WARNINGS;
+---------+------+--------------------------------------------------------------
------------------+
| Level   | Code | Message
                  |
+---------+------+--------------------------------------------------------------
------------------+
| Warning | 1301 | Result of load_file() was larger than max_allowed_packet (104
8576) - truncated |
+---------+------+--------------------------------------------------------------
------------------+
1 row in set (0.00 sec)

mysql> INSERT INTO blob_files(file) VALUE(LOAD_FILE('D:/1.jpg'));
Query OK, 1 row affected (0.05 sec)
Sign up to request clarification or add additional context in comments.

Comments

0

I'm going to post this as an answer, and I'll modify it as needed. In the comments I mentioned mysqld needs to run as administrator. Upon consideration, I realized this is actually not a good idea, since windows UAC is in place for a reason. A better option is to add the necessary permission to the folder.

Go to your My Documents folder under administrator, right click on My Pictures, go to security, and add "LOCAL SERVICE" to your permissions with the read attribute. Then your MySQL server should be able to read from that folder.

If you want to verify LOCAL SERVICE is the proper account, go to start -> run and type services.msc and press enter. Find MySQL, right click and hit properties, go to the Log On tab and see which account it runs as. This is the one you should add to the security tab of the folder with the read permissions.

Comments

0

This may be a little late but how I insert blob files when I just need them as sample data is like this:

  1. Using MysqlWorkbench I enter a record into my blob table without applying the insert.
  2. I right-click the blob field, open value editor then upload an image there.
  3. Now before applying the insert I copy the row and paste it repeatedly (a procedure loop can be used as well)

I do this same thing when updating blob fields as well except in the WHERE clause I would use WHERE primaryKey >= this value this would update all the samples

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.