MySQL 5.6 DATETIME doesn't accept milliseconds/microseconds

Running MySQL 5.6.7-rc which allegedly supports fractional seconds in time values. Right...

Try this in MySQL Workbench 5.2.44:

CREATE TABLE T (dt DATETIME);
INSERT INTO T (dt) VALUES ('2012-11-12 13:54:00.123');
SELECT dt FROM T;

The output is this:

2012-11-12 13:54:00

What am I missing here?


Solution 1:

Found the answer. Data type should be DATETIME(6) for microseconds and DATETIME(3) for milliseconds.

TIME and TIMESTAMP column types also support fractional seconds with the same syntax.

For more information, consult the MySQL Reference on Fractional Seconds.

Solution 2:

to get microseconds in mysql, call

SELECT MICROSECOND(dt) FROM T;