I cannot seem to store binary data as a BLOB.
I used the following to create a table capable of holding a BLOB:
CREATE TABLE blob_table
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
binary_stuff BLOB,
PRIMARY KEY (id)
);
The table was created OK.
Since binary data is basically anything, I created a short one line text
file named "blob.txt" and loaded that:
INSERT INTO blob_table
SET binary_stuff = LOAD_FILE("/home/mark/sql_stuff/blob.txt");
I got messages that the INSERT was successful.
Then, I checked to see if anything is there, but the column
"binary_stu ff" seems to be empty:
mysql> select * from blob_table;
+----+--------------+
| id | binary_stuff |
+----+--------------+
| 1 | NULL |
+----+--------------+
1 row in set (0.00 sec)
Alternatively:
mysql> select id, length(binary_s tuff) from blob_table;
+----+----------------------+
| id | length(binary_s tuff) |
+----+----------------------+
| 1 | NULL |
+----+----------------------+
1 row in set (0.00 sec)
Now, LOAD_FILE (according to the MySQL on-line docs) works as long as
the stuff you are loading does not exceed "max_allowed_pa cket" in size,
so I used SHOW VARIABLES to find that "max_allowed_pa cket" is 1048576.
My short text file is certainly shorter than that.
An ideas what is happening?
I used the following to create a table capable of holding a BLOB:
CREATE TABLE blob_table
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
binary_stuff BLOB,
PRIMARY KEY (id)
);
The table was created OK.
Since binary data is basically anything, I created a short one line text
file named "blob.txt" and loaded that:
INSERT INTO blob_table
SET binary_stuff = LOAD_FILE("/home/mark/sql_stuff/blob.txt");
I got messages that the INSERT was successful.
Then, I checked to see if anything is there, but the column
"binary_stu ff" seems to be empty:
mysql> select * from blob_table;
+----+--------------+
| id | binary_stuff |
+----+--------------+
| 1 | NULL |
+----+--------------+
1 row in set (0.00 sec)
Alternatively:
mysql> select id, length(binary_s tuff) from blob_table;
+----+----------------------+
| id | length(binary_s tuff) |
+----+----------------------+
| 1 | NULL |
+----+----------------------+
1 row in set (0.00 sec)
Now, LOAD_FILE (according to the MySQL on-line docs) works as long as
the stuff you are loading does not exceed "max_allowed_pa cket" in size,
so I used SHOW VARIABLES to find that "max_allowed_pa cket" is 1048576.
My short text file is certainly shorter than that.
An ideas what is happening?