← Back to MySQL Course | Chapter 3: Data Types | Lesson 7 of 8

BLOB और Binary Types

एक BLOB pictures या sounds जैसी raw चीज़ों के लिए एक storage locker जैसा है, उन्हें words की तरह पढ़े बिना exactly वैसे ही रखते हुए जैसे वे हैं।
Syntax
sql
column_name BLOB
column_name VARBINARY(max_length)

BLOB Types

BLOB (Binary Large Object) variable size का raw binary data store करता है — images, audio clips, encrypted payloads — एक opaque byte sequence की तरह जिसे MySQL interpret या validate करने की कोशिश नहीं करता।

उदाहरण: BLOB Types

sql
CREATE TABLE files (id INT, content BLOB);

VARBINARY Type

VARBINARY VARCHAR का binary counterpart है: यह text के बजाय exact byte sequences store करता है, जो इसे बड़ी files के बजाय hashes या tokens जैसी छोटी, fixed-format binary values के लिए सही fit बनाता है।

उदाहरण: VARBINARY Type

sql
CREATE TABLE tokens (hash VARBINARY(64));

BLOB Sizes

MySQL चार BLOB sizes offer करता है — TINYBLOB, BLOB, MEDIUMBLOB, और LONGBLOB — जो सिर्फ अपनी maximum storage capacity में अलग हैं, इसलिए आप realistically store करने की उम्मीद करने वाले सबसे बड़े file size के आधार पर चुनते हैं।

उदाहरण: BLOB Sizes

sql
CREATE TABLE uploads (
  thumbnail TINYBLOB,
  photo BLOB,
  video MEDIUMBLOB,
  archive LONGBLOB
);

BLOB Data Retrieve करना

क्योंकि BLOB data human-readable नहीं है, HEX() जैसे functions आपको इसकी raw bytes को एक hexadecimal string की तरह inspect करने देते हैं, जो अक्सर किसी query result से binary content देखने का इकलौता practical तरीका है।

उदाहरण: Retrieving BLOB Data

sql
CREATE TABLE files (content BLOB);
INSERT INTO files VALUES (0x48656C6C6F);
SELECT HEX(content) FROM files;

BLOB Restrictions

BLOB columns की कोई DEFAULT value नहीं हो सकती, और एक को index करने के लिए एक prefix length specify करना ज़रूरी है (सिर्फ पहले N bytes index करना) क्योंकि पूरे बड़े binary object को सीधे index करना support नहीं है।

उदाहरण: BLOB Restrictions

sql
-- BLOB columns cannot have a DEFAULT value
CREATE TABLE files (content BLOB, INDEX idx_content (content(100)));

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. बड़े images या files को BLOB columns में store करना और database को धीमा करना, जबकि file path अक्सर बेहतर है।
  2. कई rows पर SELECT * से एक BLOB column select करना, जो बहुत सारा data transfer करता है।
  3. size 64 KB से ज़्यादा हो सकने पर BLOB चुनना, जब MEDIUMBLOB या LONGBLOB चाहिए।
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.