Data Type Storage Requirements
The storage requirements for each of the data types supported by MySQL are listed here by category.
The maximum size of a row in a MyISAM table is 65,535 bytes. Each BLOB and TEXT column accounts for only nine to twelve bytes toward this size. This limitation may be shared by other storage engines as well.
Important
For tables using the NDBCluster storage engine, there is the factor of 4-byte alignment to be taken into account when calculating storage requirements. This means that all NDB data storage is done in multiples of 4 bytes. Thus, a column value that would take 15 bytes in a table using a storage engine other than NDB requires 16 bytes in an NDB table. This requirement applies in addition to any other considerations that are discussed in this section. For example, in NDBCluster tables, the TINYINT, SMALLINT, MEDIUMINT, and INTEGER (INT) column types each require 4 bytes storage per record due to the alignment factor.
In addition, when calculating storage requirements for Cluster tables, you must remember that every table using the NDBCluster storage engine requires a primary key; if no primary key is defined by the user, then a “hidden” primary key will be created by NDB. This hidden primary key consumes 31-35 bytes per table record.
You may find the ndb_size.pl utility to be useful for estimating NDB storage requirements. This Perl script connects to a current MySQL (non-Cluster) database and creates a report on how much space that database would require if it used the NDBCluster storage engine. See Section 16.11.15, “ndb_size.pl — NDBCluster Size Requirement Estimator”, for more information.
Storage Requirements for Numeric Types
| Data Type | Storage Required |
TINYINT |
1 byte |
SMALLINT |
2 bytes |
MEDIUMINT |
3 bytes |
INT, INTEGER |
4 bytes |
BIGINT |
8 bytes |
FLOAT( |
4 bytes if 0 <= p <= 24, 8 bytes if 25 <= p <= 53 |
FLOAT |
4 bytes |
DOUBLE [PRECISION], REAL |
8 bytes |
DECIMAL(, NUMERIC( |
Varies; see following discussion |
BIT( |
approximately (M+7)/8 bytes |
Values for DECIMAL (and NUMERIC) columns are represented using a binary format that packs nine decimal (base 10) digits into four bytes. Storage for the integer and fractional parts of each value are determined separately. Each multiple of nine digits requires four bytes, and the “leftover” digits require some fraction of four bytes. The storage required for excess digits is given by the following table:
| Leftover Digits | Number of Bytes |
| 0 | 0 |
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 2 |
| 5 | 3 |
| 6 | 3 |
| 7 | 4 |
| 8 | 4 |
Storage Requirements for Date and Time Types
| Data Type | Storage Required |
DATE |
3 bytes |
TIME |
3 bytes |
DATETIME |
8 bytes |
TIMESTAMP |
4 bytes |
YEAR |
1 byte |
The storage requirements shown in the table arise from the way that MySQL represents temporal values:
-
DATE: A three-byte integer packed asDD+MM×32 +YYYY×16×32 -
TIME: A three-byte integer packed asDD×24×3600 +HH×3600 +MM×60 +SS -
DATETIME: Eight bytes:-
A four-byte integer packed as
YYYY×10000 +MM×100 +DD -
A four-byte integer packed as
HH×10000 +MM×100 +SS
-
-
TIMESTAMP: A four-byte integer representing seconds UTC since the epoch ('1970-01-01 00:00:00'UTC) -
YEAR: A one-byte integer
Storage Requirements for String Types
In the following table, M represents the declared column length in characters for non-binary string types and bytes for binary string types. L represents the actual length in bytes of a given string value.
| Data Type | Storage Required |
CHAR( |
M × w bytes, 0 <= 255, where w is the number of bytes required for the maximum-length character in the character set |
BINARY( |
M bytes, 0 <= 255 |
VARCHAR(, VARBINARY( |
L + 1 bytes if column values require 0 – 255 bytes, L + 2 bytes if values may require more than 255 bytes |
TINYBLOB, TINYTEXT |
L + 1 bytes, where L < 28 |
BLOB, TEXT |
L + 2 bytes, where L < 216 |
MEDIUMBLOB, MEDIUMTEXT |
L + 3 bytes, where L < 224 |
LONGBLOB, LONGTEXT |
L + 4 bytes, where L < 232 |
ENUM(' |
1 or 2 bytes, depending on the number of enumeration values (65,535 values maximum) |
SET(' |
1, 2, 3, 4, or 8 bytes, depending on the number of set members (64 members maximum) |
Variable-length string types are stored using a length prefix plus data. The length prefix requires from one to four bytes depending on the data type, and the value of the prefix is L (the byte length of the string). For example, storage for a MEDIUMTEXT value requires L bytes to store the value plus three bytes to store the length of the value.
To calculate the number of bytes used to store a particular CHAR, VARCHAR, or TEXT column value, you must take into account the character set used for that column and whether the value contains multi-byte characters. In particular, when using the utf8 Unicode character set, you must keep in mind that not all utf8 characters use the same number of bytes and can require up to three bytes per character. For a breakdown of the storage used for different categories of utf8 characters, see Section 9.1.8, “Unicode Support”.
VARCHAR, VARBINARY, and the BLOB and TEXT types are variable-length types. For each, the storage requirements depend on these factors:
-
The actual length of the column value
-
The column's maximum possible length
-
The character set used for the column, because some character sets contain multi-byte characters
For example, a VARCHAR(255) column can hold a string with a maximum length of 255 characters. Assuming that the column uses the latin1 character set (one byte per character), the actual storage required is the length of the string (L), plus one byte to record the length of the string. For the string 'abcd', L is 4 and the storage requirement is five bytes. If the same column is instead declared to use the ucs2 double-byte character set, the storage requirement is 10 bytes: The length of 'abcd' is eight bytes and the column requires two bytes to store lengths because the maximum length is greater than 255 (up to 510 bytes).
Note
The effective maximum number of bytes that can be stored in a VARCHAR or VARBINARY column is subject to the maximum row size of 65,535 bytes, which is shared among all columns. For a VARCHAR column that stores multi-byte characters, the effective maximum number of characters is less. For example, utf8 characters can require up to three bytes per character, so a VARCHAR column that uses the utf8 character set can be declared to be a maximum of 21,844 characters.
The NDBCLUSTER storage engine in MySQL 5.1 supports variable-width columns. This means that a VARCHAR column in a MySQL Cluster table requires the same amount of storage as it would using any other storage engine, with the exception that such values are 4-byte aligned. Thus, the string 'abcd' stored in a VARCHAR(50) column using the latin1 character set requires 8 bytes (rather than 6 bytes for the same column value in a MyISAM table). This represents a change in behavior from earlier versions of NDBCLUSTER, where a VARCHAR(50) column would require 52 bytes storage per record regardless of the length of the string being stored.
TEXT and BLOB columns are implemented differently in the NDB Cluster storage engine, wherein each row in a TEXT column is made up of two separate parts. One of these is of fixed size (256 bytes), and is actually stored in the original table. The other consists of any data in excess of 256 bytes, which is stored in a hidden table. The rows in this second table are always 2,000 bytes long. This means that the size of a TEXT column is 256 if size <= 256 (where size represents the size of the row); otherwise, the size is 256 + size + (2000 – (size – 256) % 2000).
The size of an ENUM object is determined by the number of different enumeration values. One byte is used for enumerations with up to 255 possible values. Two bytes are used for enumerations having between 256 and 65,535 possible values. See Section 10.4.4, “The ENUM Type”.
The size of a SET object is determined by the number of different set members. If the set size is N, the object occupies ( bytes, rounded up to 1, 2, 3, 4, or 8 bytes. A N+7)/8SET can have a maximum of 64 members. See Section 10.4.5, “The SET Type”.
게시글 목록
| 번호 | 제목 |
|---|---|
| 13454 | |
| 29442 |
HTML
php 에서 xml 자유롭게 쓰기
4
|
| 13451 | |
| 13448 |
jQuery
자동등록방지코드
2
|
| 13446 | |
| 13445 |
jQuery
ajax modal window (ajax 모달창)
|
| 13442 |
jQuery
간단하게 Round, 그라디언트 처리하기!!
2
|
| 13439 | |
| 13437 | |
| 13434 | |
| 13429 | |
| 13425 | |
| 13423 | |
| 13418 |
jQuery
탭메뉴
4
|
| 13410 | |
| 13408 | |
| 13407 | |
| 13406 |
기타
수학 함수 모음
|
| 29441 |
HTML
변수 함수 모음
|
| 13405 |
JavaScript
URL 함수 모음
|
| 13404 |
기타
디렉토리 함수 모음
|
| 13401 |
JavaScript
파일 함수 모음
2
|
| 13400 |
기타
문자열 함수 모음
|
| 13399 | |
| 13395 |
MySQL
Mysql 날짜관련 함수 모음
3
|
| 13391 |
jQuery
jquery scrolling menu
3
|
| 29435 | |
| 13389 |
JavaScript
정규 표현식 입문서? "손에 잡히는 정규 표현식"
1
|
| 13386 |
정규표현식
정규표현식 검사기
2
|
| 13381 |
jQuery
Jquery 체크박스 사용법
4
|
| 13377 |
Flash
sql 인젝션 복구쿼리
3
|
| 13370 |
JavaScript
페이지 자동이동하기 팁(여기 없는 거)
6
|
| 13367 |
MySQL
mysql 유저 생성, 권한 부여
2
|
| 13366 |
JavaScript
자바스크립트 쿠키 생성, 삭제
|
| 13364 | |
| 13362 | |
| 29432 | |
| 29428 |
HTML
엔터치면 다음칸으로 이동.
3
|
| 13361 |
jQuery
IBM 한국 jQuery 기술자료
|
| 13360 | |
| 13358 | |
| 13354 | |
| 13351 |
JavaScript
이미지 자동으로 사이즈 정해주는 방법은 어떻게 하나요?
2
|
| 29427 | |
| 13346 | |
| 13340 |
jQuery
lightbox 수정 2차 완료
5
|
| 13337 | |
| 13334 | |
| 13328 |
jQuery
선물입니다.
5
|
| 13326 |
JavaScript
virtual hosts
1
|
| 13325 |
기타
asp 글 삭제하기
|
| 13324 |
기타
asp 글 수정하기
|
| 13323 |
기타
asp 글읽기
|
| 29426 |
HTML
asp 목록보기
|
| 13322 |
JavaScript
asp 저장하기
|
| 13321 |
기타
asp 글쓰기
|
| 13315 | |
| 29424 | |
| 13312 |
JavaScript
오픈 api 에 사용할 XML 파서 따끈한거 테스트 부탁드립니다....^^
2
|
| 29422 | |
| 25114 | |
| 13308 | |
| 13307 | |
| 13305 |
JavaScript
if문 축약해 사용하기
1
|
| 13304 |
JavaScript
체크 상자 몇개 이상 채크시 경고창 및 개수이상 클릭못하게하기
|
| 25111 | |
| 29421 |
HTML
테이블 복사
|
| 13301 | |
| 13299 | |
| 13296 |
jQuery
별거는 아니지만
2
|
| 13292 |
JavaScript
[VIM] vim으로 소스코드 범위 설정하여 영역을 접고 펴기
3
|
| 13291 | |
| 13290 |
JavaScript
"웹표준에 관한 타입 선언"- 필요하신 분은 참고하세요...
|
| 13289 | |
| 13288 | |
| 13287 | |
| 13286 | |
| 13285 | |
| 13284 |
기타
아파치 설치문서
|
| 29420 | |
| 13283 |
JavaScript
글자 쪼개서 배열에 넣기
|
| 13277 | |
| 13274 | |
| 13266 |
MySQL
MySQL 상태보기 (MySQL튜닝하기)
7
|
| 13265 | |
| 13262 | |
| 13261 |
jQuery
링크 관련 활용
|
| 13259 |
MySQL
Slow Query Log
1
|
| 13254 |
JavaScript
폼의 첫번째 입력가능한 필드에 FOCUS 주기
4
|
| 13250 | |
| 29419 | |
| 13242 | |
| 13241 | |
| 13236 | |
| 13235 | |
| 29418 |
HTML
레이어 좌표 이동-1
|
| 29417 |
HTML
프레임 제어속성
|
| 13234 | |
| 13233 | |
| 13231 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기