I want to know the difference in detail between CHAR and VARCHAR data types in MySQL. Any help pls?
The CHAR and VARCHAR data types store non-binary strings (that is, strings of characters that have a character set and collation). These types differ in terms of their maximum allowable length and in how trailing spaces are handled.
The CHAR data type is a fixed-length type. The length should be a number from 0 to 255. The CHAR data type holds strings up to the length specified in the column definition. Values in a CHAR column always take the same amount of storage. For example, a column defined as CHAR(30) requires 30 characters for each value, even empty values. Values shorter than the designated length are padded with spaces to that length when they are stored. Trailing spaces are removed from CHAR values when they are retrieved, so retrieved values might not be the same length as when stored.
VARCHAR is a variable-length data type. VARCHAR columns are defined similarly to CHAR columns, but the maximum length can be a number up to 65,535. (The actual allowable maximum length is a few characters less due to internal restrictions imposed by storage engines.) A string stored into a VARCHAR column takes only the number of characters required to store it, plus one or two bytes to record the string's length. (One byte for columns declared with a length less than 256, two bytes otherwise.) Values in a VARCHAR column are stored as given. Trailing spaces are not removed or added for storage or retrieval.
With CHAR data type column, search seems working faster than VARCHAR data type column.