The term BLOB stands for Binar Large OBject, and therefore, as you would think, the BLOB data type is most useful for binary data in excess of 65,536 bytes in size. The main other difference between the BLOB and BINARY data types is that BLOBs cannot have default values.
- TINYBLOB(n) Up to n (<= 255) Treated as binary data—no character set
- BLOB(n) Up to n (<= 65535) Treated as binary data—no character set
- MEDIUMBLOB(n) Up to n (<= 1.67e+7) Treated as binary data—no character set
- LONGBLOB(n) Up to n (<= 4.29e+9) Treated as binary data—no character set
MySQL supports various numeric data types, from a single byte up to doubleprecision floating-point numbers. Although the most memory that a numeric field can use up is 8 bytes, you are well advised to choose the smallest data type that will adequately handle the largest value you expect. This will help keep your databases small and quickly accessible.
Next lists the numeric data types supported by MySQL and the ranges of values they can contain. In case you are not acquainted with the terms, a signed number is one with a possible range from a minus value, through 0, to a positive one; and anunsigned number has a value ranging from 0 to a positive one. They can both hold the same number of values; just picture a signed number as being shifted halfway to the left so that half its values are negative and half are positive. Note that floating-point
values (of any precision) may only be signed.
Data type / Bytes used / Minimum value / Maximum value / Unsigned min / Unsigned max
TINYINT 1 –128 127 0 255
SMALLINT 2 –32768 32767 0 65535
MEDIUMINT 3 –8.38e+6 8.38e+6 0 1.67e+7
INT / INTEGER 4 –2.15e+9 2.15e+9 0 4.29e+9
BIGINT 8 –9.22e+18 9.22e+18 0 1.84e+19
FLOAT 4 –3.40e+38 3.4e+38 – –
DOUBLE / REAL 8 –1.80e+308 1.80e+308 – –
To specify whether a data type is unsigned, use the UNSIGNED qualifier. The following example creates a table called tablename with a field in it called fieldname of the data type UNSIGNED INTEGER:
CREATE TABLE tablename (fieldname INT UNSIGNED);
When creating a numeric field, you can also pass an optional number as a parameter, like this:
CREATE TABLE tablename (fieldname INT(4));
But you must remember that, unlike with the BINARY and CHAR data types, this parameter does not indicate the number of bytes of storage to use. It may seem counterintuitive, but what the number actually represents is the display width of the data in the field when it is retrieved. It is commonly used with the ZEROFILL qualifier, like
this:
CREATE TABLE tablename (fieldname INT(4) ZEROFILL);
What this does is cause any numbers with a width of less than four characters to be padded with one or more zeros, sufficient to make the display width of the field four characters long. When a field is already of the specified width or greater, no padding takes place.