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.

Aug 102010
 

Change the maximum allowed binary log file size in MySQL

Answer:

By default, the MySQL's maximum binary log file is 1073741824 bytes (1GB).

If you want to change it, edit the MySQL configurations, e.g. /etc/my.cnf

[mysqld]
...
...
max_binlog_size 4294967296

Restart MySQL to take effect.

# /sbin/service mysqld restart

Now the new maximum binary log file is set to 4GB.

Aug 022010
 

Sleep in MySQL

Answer:

In MySQL, you can issue an query to sleep(), e.g.

mysql> SELECT SLEEP(2);
+----------+
| SLEEP(2) |
+----------+
|        0 |
+----------+
1 row in set (2.00 sec)
Jul 202010
 

What is the storage overhead in using VARCHAR in MySQL

Answer:

MySQL allow VARCHAR to have length from a value from 0 to 65,535.

Since MySQL need to store the length of each VARCHAR field, in additional to the actual data itself, it needs 16 bits = 2 bytes for each field. But if the length of VARCHAR during table creation is less than or equal to 255, it only take 1 byte per field.

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

Jul 192010
 

Compare binary value in MySQL

Answer:

Assume you have the following table.

mysql> CREATE TABLE t ( 
    c BINARY(3)
) ENGINE = INNODB;

And you insert some sample value...

mysql> INSERT INTO t VALUES ('fo');
mysql> INSERT INTO t VALUES ('foo');

Finally you select it

mysql> SELECT * FROM t WHERE c = 'foo';
+------+
| c    |
+------+
| foo  |
+------+
1 row in set (0.00 sec)

mysql> SELECT * FROM t WHERE c = 'fo';
Empty set (0.00 sec)

Why you cannot find the result in the second query? Because the column is BINARY, the trailing space(s) is not ignored like this.

You need to query like...

mysql> SELECT * FROM WHERE c = 'fo\0';
+------+
| c    |
+------+
| fo   |
+------+
1 row in set (0.00 sec)

As you can see, you need to append the the 0x00 (the zero byte). at the end of the character.

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