The difference between char and varchar in the MySQL tutorial is used to store strings, except that they are stored in a different way, Char has a fixed length, and varchar is a variable-length character type.
The difference between char and varchar
char (13) length fixed, such as ' www.111cn.net ' storage requires space 13 characters
varchar (13) variable length as ' www.111cn.net ' requires storage space of 14 characters,
From the above you can see that the char length is fixed, no matter how much data you store it will be fixed length. The varchar is a variable length but he wants to add 1 characters to the total length, which is used to store the location. So the actual application of the user can be based on their own data types to do.
And look at Char, the difference between speed and varchar .
Mysal>create Tabe AB (v varchar (4), C char (4));
Query OK, 0 rows affected (0.02 sec)
Mysql>insert into ABC values (' Ab ', ' ab ')
Query OK, 1 row affected (0.00 sec);
Mysql->select concat (V, ' + '), concat (c, ' + ') Form ABC
AB + | ab+
1rows in Set (0.00 sec)
As can be seen from the above, for some reason char fixed length, so in processing speed than varchar a lot faster, but the cost of storage space, so the storage is small, but the speed of the requirements can use the char type, conversely can be used varchar type to instance.
Indicate:
When a char character type is used, the content must be processed when there is space behind it, or the space will be automatically deleted.
Jian Yi:
The MyISAM storage engine recommends a fixed length, with data columns instead of variable-length data columns.
The memory storage engine currently uses fixed data row storage, so it doesn't matter whether you use a char varchar column,
InnoDB storage Engine is intended to use varchar type
All right, this site original tutorial reproduced annotated source www.111cn.net/database/database.html