前导空格认为是不相等, 后导空格自动略去, 认为是相等.

mysql> select 'a'='a','a'=' a','a'='a ','a'=' a ','a'<=>'a','a'<=>' a','a'<=>'a ','a'<=>' a ';
+---------+----------+----------+-----------+-----------+------------+------------+-------------+
| 'a'='a' | 'a'=' a' | 'a'='a ' | 'a'=' a ' | 'a'<=>'a' | 'a'<=>' a' | 'a'<=>'a ' | 'a'<=>' a ' |
+---------+----------+----------+-----------+-----------+------------+------------+-------------+
|       1 |        0 |        1 |         0 |         1 |          0 |          1 |           0 |
+---------+----------+----------+-----------+-----------+------------+------------+-------------+

使用一个 BINARY 强制二进制比较(大小写敏感, 不自动截取)

mysql> select BINARY'a'='a ', BINARY'a'<=>'a ';
+----------------+------------------+
| BINARY'a'='a ' | BINARY'a'<=>'a ' |
+----------------+------------------+
|              0 |                0 |
+----------------+------------------+

NULL 跟任何值比较都是 NULL. <=> 为 NULL安全的操作

mysql> select ''=null, ''!=null, ''<>null, ''<=>null, '' is null, '' is not null;
+---------+----------+----------+-----------+------------+----------------+
| ''=null | ''!=null | ''<>null | ''<=>null | '' is null | '' is not null |
+---------+----------+----------+-----------+------------+----------------+
|    NULL |     NULL |     NULL |         0 |          0 |              1 |
+---------+----------+----------+-----------+------------+----------------+

mysql> select null=null, null!=null, null<>null, null<=>null, null is null, null is not null;
+-----------+------------+------------+-------------+--------------+------------------+
| null=null | null!=null | null<>null | null<=>null | null is null | null is not null |
+-----------+------------+------------+-------------+--------------+------------------+
|      NULL |       NULL |       NULL |           1 |            1 |                0 |
+-----------+------------+------------+-------------+--------------+------------------+