LONGBLOB

LONGBLOB is a data type in SQL used for storing binary large object that can hold a variable amount of data. This data type can store up to 4GB of binary data, making it suitable for storing large amounts of binary information such as images or files. The LONGBLOB data type is typically used when the size of the BLOB data is unpredictable or can exceed the maximum allowable size of other BLOB types. As a binary string type, its values are stored as strings that can contain bytes with any value from 0 to 255.

Example

CREATE TABLE example_table (
id INT AUTO_INCREMENT,
longblob_column LONGBLOB,
PRIMARY KEY(id)
);
INSERT INTO example_table (longblob_column)
VALUES(LOAD_FILE('/path/to/your/image.jpg'));

Output

To display the output, the SELECT statement can be used:

SELECT * FROM example_table;

This may output something similar to (since LONGBLOB data are binary, it won’t be readable):

+----+------------------+
| id | longblob_column |
+----+------------------+
| 1 | Binary data |
+----+------------------+

Explanation

In the example, a table named example_table is created with an id column and a LONGBLOB column. The id is an integer that auto-increments, and the longblob_column stores binary data. An image is inserted into the longblob_column using LOAD_FILE(). This function loads the image file from the provided path and it’s stored as binary data in the LONGBLOB column.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.