Jul 152010
Trailing spaces of char in MySQL
Answer:
MySQL collations are of type PADSPACE. This means that all CHAR and VARCHAR values in MySQL are compared without regard to any trailing spaces.
E.g.
1. Create a table
mysql> CREATE TABLE t1 (
c CHAR(10),
v VARCHAR(10)
) ENGINE = INNODB;
2. Insert some data
mysql> INSERT INTO t1 VALUES ('foo', 'bar');
3. Select the data back
mysql> SELECT COUNT(*) FROM t1 WHERE c = 'foo';
+----------+
| count(*) |
+----------+
| 1 |
+----------+
1 row in set (0.00 sec)
mysql> SELECT COUNT(*) FROM t1 WHERE c = 'foo ';
+----------+
| count(*) |
+----------+
| 1 |
+----------+
1 row in set (0.00 sec)
As you can see, the trailing spaces makes no difference.