Joke Collection Website - Joke collection - Problems of char type in mysql

Problems of char type in mysql

char is a fixed-length type, while varchar is a variable-length type. Their differences are as follows:

In a data column of type char (m), each value takes up m bytes. If a length is less than m, MySQL will fill it with space characters on its right. (Those filled space characters will be removed in the retrieval operation) In a data column of type varchar(M), Each value only takes up just enough bytes plus one byte to record its length (that is, the total length is L+1 bytes).

Rules used in MySQL to judge whether it is necessary to convert the column type

1. In a data table, if the length of each data column is fixed, the length of each data row will also be fixed.

2. As long as there is one data column in the data table. Then the length of each data row is variable.

3. If the length of a data row in a data table is variable, MySQL will convert the fixed-length data column in this data table into the corresponding variable-length type in order to save storage space.

Exception: char data columns with a length less than 4 characters will not be converted into varchar type.

I hope it will be helpful to you.