Introduction
BLOB and binary types let you store data like pictures, music, or any files in a database.
CREATE TABLE table_name ( column_name BLOB, column_name BINARY(n), column_name VARBINARY(n) );
CREATE TABLE images ( id INT PRIMARY KEY, photo BLOB );
CREATE TABLE files ( id INT PRIMARY KEY, file_data VARBINARY(255) );
CREATE TABLE keys ( id INT PRIMARY KEY, key_data BINARY(16) );
CREATE TABLE documents ( id INT PRIMARY KEY, doc_name VARCHAR(50), doc_content BLOB ); INSERT INTO documents (id, doc_name, doc_content) VALUES (1, 'example.txt', LOAD_FILE('/var/lib/mysql-files/example.txt')); SELECT id, doc_name, LENGTH(doc_content) AS content_size FROM documents;
files(id INT, data BLOB), what will the following query return?SELECT LENGTH(data) FROM files WHERE id = 1;
CREATE TABLE images (id INT, img BINARY(255));
id INT and picture. You expect pictures up to 2MB. Which data type should you choose for picture and why?Pass the test and this pattern moves unknown