content_image/834676.jpg
); 

•The BINARY  attribute is a nonstandard MySQL extension that is shorthand for specifying the binary ( _bin ) collation of the column character set (or of the table default character set if no column character set is specified). In this case, comparison and sorting are based on numeric character code values. Suppose that you specify a table using this definition: 

CREATE TABLE t ( c1 VARCHAR(10) CHARACTER SET latin1 BINARY, c2 TEXT BINARY ) CHARACTER SET utf8mb4; 

The resulting table has this definition: 

CREATE TABLE t ( c1 VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin, c2 TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin ) CHARACTER SET utf8mb4; 

In MySQL 8.0, this nonstandard use of the BINARY  attribute is ambiguous because the utf8mb4 character set has multiple _bin  collations. As of MySQL 8.0.17, the BINARY  attribute is deprecated and you should expect support for it to be removed in a future version of MySQL. Applications should be adjusted to use an explicit _bin  collation instead. 

The use of BINARY  to specify a data type or character set remains unchanged. 

•The ASCII  attribute is shorthand for CHARACTER SET latin1 . 

•The UNICODE  attribute is shorthand for CHARACTER SET ucs2 . 

Character column comparison and sorting are based on the collation assigned to the column. For the CHAR , VARCHAR , TEXT , ENUM , and SET  data types, you can declare a column with a binary ( _bin ) collation or the BINARY  attribute to cause comparison and sorting to use the underlying character code values rather than a lexical ordering. 

For additional information about use of character sets in MySQL, see Chapter 10, Character Sets, Collations, Unicode . 

• [NATIONAL] CHAR[( M )] [CHARACTER SET charset_name ] [COLLATE collation_name ] 

A fixed-length string that is always right-padded with spaces to the specified length when stored. M represents the column length in characters. The range of M  is 0 to 255. If M  is omitted, the length is 1. 

<img src='content_image/834676.jpg'>

## Note 

Trailing spaces are removed when CHAR  values are retrieved unless the PAD_CHAR_TO_FULL_LENGTH  SQL mode is enabled. 

CHAR  is shorthand for CHARACTER . NATIONAL CHAR  (or its equivalent short form, NCHAR ) is the standard SQL way to define that a CHAR  column should use some predefined character set. MySQL uses utf8  as this predefined character set. Section 10.3.7, “The National Character Set” . 

The CHAR BYTE  data type is an alias for the BINARY  data type. This is a compatibility feature. 

MySQL permits you to create a column of type CHAR(0) . This is useful primarily when you must be compliant with old applications that depend on the existence of a column but that do not actually use its value. CHAR(0)  is also quite nice when you need a column that can take only two values: A column 

