Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Jul 172010
 

What are the difference between CHAR BINARY and BINARY type in MySQL

Answer:

For CHAR BINARY, the BINARY keyword does not cause the column to store binary value, instead, it cause the column to use binary collation only. The actual character set used depend on the system.

For BINARY column, the actual data is treated as binary, so no charset and collation rules apply.

Reference: http://dev.mysql.com/doc/refman/5.1/en/binary-varbinary.html

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.

Reference: http://dev.mysql.com/doc/refman/5.1/en/char.html

Jul 132010
 

How to create a patch

Answer:

Let say you have two folders, foo and bar.

The folder bar is originally copied from the folder foo, but later you have chanegd some files inside bar.

Now you want to create a patch (We will see later, when this patch applied to foo, it will produce the same contents as in bar).

# diff -crB foo bar > bar.patch