将BLOB值插入MySQL数据库 [英] Insert a BLOB value into MySQL database
本文介绍了将BLOB值插入MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个MYSQL数据库,其列名为BLOB类型的img.
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')
有效!
但是这样:
LOAD_FILE('C:/Documents and Settings/Administrator/My Documents/My Pictures/picture.jpg')
它不起作用,它告诉我列img不能为空!
it doesn't work and it tells me that the column img cannot be null !
在这两种情况下,文件都存在,并且我以root用户(所有特权)连接到数据库,所以我不明白为什么会收到此错误.
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.
预先感谢
推荐答案
也许 max_allowed_packet
1.jpg是小图片,而2.jpg是大图片
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)
这篇关于将BLOB值插入MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文