mysql 字符串比较_Mysql字符类型比较

一、 binary和char比较:

binary 字节为单位,char字符为单位,字符占几个字节取决于字符集

binary  比较规则基于字节值,char基于字符,即使是_bin的比较规则

范围都0-255字节,char对于不同字符集,可以存取的字节数不同

排序和比较规则都会根据字符码值,而不是词典顺序,如果采用binary那么是区分大小写的,和我们常用的utf8_general_ci相冲突

相同特性,摘自官方文档:

Specifying the CHARACTER SET binary attribute for a character data type causes the column

to be created as the corresponding binary data type: CHAR becomes BINARY, VARCHAR becomes VARBINARY , and TEXT becomes BLOB . For the ENUM and SET data types, this does not occur;

以下两种表定义是等义的:

CREATE TABLE t

(

c1 VARCHAR(10) CHARACTER SET binary,

c2 TEXT CHARACTER SET binary,

c3 ENUM('a','b','c') CHARACTER SET binary

);

CREATE TABLE t

(

c1 VARBINARY(10),

c2 BLOB,

c3 ENUM('

你可能感兴趣的:(mysql,字符串比较)