The length of the ENUM data type in MySQL depends on the number of characters stored and the number of bytes in the character set. The calculation formula is: number of characters stored × number of bytes in the character set.
Length calculation of ENUM data type in MySQL
The ENUM data type in MySQL is used to store a set of preset defined value. Its length is determined by the following factors:
1. Number of characters stored
The number of characters stored for each ENUM value. This is the most important factor in the length of this type.
2. Character set
The character set determines the number of bytes for each character. For example, UTF-8 takes 1 to 4 bytes per character.
Calculation formula:
The length of the ENUM data type (bytes) = the number of characters stored × the number of bytes in the character set
Example:
Suppose we have an ENUM column named "gender" whose values include "male", "female" and "other", using the UTF-8 character set.
Thus, the length of the ENUM data type for the "gender" column is calculated as follows:
Therefore, the total length of this ENUM column is 6 bytes.
The above is the detailed content of How to calculate the length of enum in mysql. For more information, please follow other related articles on the PHP Chinese website!