CREATE TABLE `datetimetest` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
);
上記のようなテーブルを用意します。datetimeは括弧なしなので秒単位です。
mysql> INSERT INTO datetimetest set time='2014-01-01 00:00:00.499';
mysql> INSERT INTO datetimetest set time='2014-01-01 00:00:00.500';
mysql> SELECT * FROM datetimetest;
+----+---------------------+
| id | time |
+----+---------------------+
| 1 | 2014-01-01 00:00:00 |
| 2 | 2014-01-01 00:00:01 |
+----+---------------------+
こんなふうにINSERT時にミリ秒まで指定すると、ミリ秒が四捨五入されて秒が進んでしまいます。
mysql> SELECT * FROM datetimetest WHERE time<='2014-01-01 00:00:00.999';
+----+---------------------+
| id | time |
+----+---------------------+
| 1 | 2014-01-01 00:00:00 |
+----+---------------------+
mysql> SELECT * FROM datetimetest WHERE time>='2014-01-01 00:00:00.999';
+----+---------------------+
| id | time |
+----+---------------------+
| 2 | 2014-01-01 00:00:01 |
+----+---------------------+
mysql> SELECT * FROM datetimetest WHERE time>='2014-01-01 00:00:00.100';
+----+---------------------+
| id | time |
+----+---------------------+
| 2 | 2014-01-01 00:00:01 |
+----+---------------------+
条件式にミリ秒を含む時刻を指定するとそれはそのまま扱われるようです。
追記:MySQL5.5では再現しないとの情報あり。MySQL5.6以降のみで発生する現象かも?