MySQL Data Types
2020, May 23
String Types
- CHAR(size) letters, numbers and special characters fixed length size: from 0 to 255, default 1
- VARCHAR(size) letters, numbers and special characters variable length size: maximal length, 0-65535
- BINDARY(size) binary byte fixed length size: column length, default to 1
- VARBINARY(size) binary byte variable length size: maximum length
- TINYBLOB BLOBs(Binary Large Objects) max length: 255 bytes
- TINYTEXT String with maximum length 255
- TEXT(size) string with maximum 65535
- BLOB(size) BLOBs up to 65535 bytes
- MEDIUMTEXT <=4,294,967,295 characters
- MEDIUMBLOB <=16,777,215 bytes
- LONGTEXT maximum 4,294,967,295
- LONGBLOB maximum 4,294,967,295 bytes
- ENUM the list can contain 65535 values If a value is not in the list, a blank value will be inserted
- SET 64 values list
Numeric Data Types:
option: UNSIGNED: disallow negative values ZEROFILL: Automatically adds UNSIGNED to the column
- BIT(size) bit-value type 1 to 64, default 1
- TINYBIT(size) -128 to 127 or 0 to 255 size: the maximum display width
- BOOL/BOOLEAN
- SMALLINT(size)
- MEDIUMINT(size)
- INT/INTEGER(size)
- BIGINT(size)
- FLOAT(size, d) d: precision
- FLOAT(p) p: wheather to use FLOAT or DOUBLE P:0-24, FLOAT() P:25-53: DOUBLE()
- DOUBLE(size, d)
- DECIMAL/DEC(size, d)
Date and Time
- DATE format: YYYY-MM-DD
- DATETIME(fsp) a date and time combination YYYY-MM-DD hh:mm:ss DEFAULT and ON UPDATE: get initialization and updating to the current datetime
- TIMESTAMP(fsp) the number of seconds since the Unix epoch(1970-01-01 00:00:00 UTC) YYYY-MM-DD hh:mm:ss DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP: current date and time
- TIME(fsp) hh:mm:ss
- YEAR