Quite a few friends who have just come in contact with MySQL have the same problem with the storage and display of milliseconds. Since the MySQL data type only provides DateTime, TIMESTAMP, Time, DATE and year of these types of times, and the minimum unit of datetime and TIMESTAMP is seconds, there is no function that stores the millisecond level. However, MySQL can recognize the millisecond portion of time. And there are a number of ways we can get milliseconds, like functions: Microsecond and so on.
I'll give you a simple example to store the seconds before and after.
For the application of the Time field as a primary key, we can create the following table for the corresponding transformation:
Mysql> CREATE TABLE Mysql_microsecond (log_time_prefix timestamp NOT null default 0, Log_time_suffix mediumint not nul L default 0) engine Innnodb;
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Mysql> ALTER TABLE Mysql_microsecond add primary key (Log_time_prefix, log_time_suffix);
Query OK, 0 rows affected (0.01 sec)
records:0 duplicates:0 warnings:0
mysql> Set @a = Convert (Concat (now (), '. 222009 '), datetime);
Query OK, 0 rows Affected (0.00 sec)
mysql> INSERT INTO Mysql_microsecond select Date_format (@a, '%y-%m-%d%h-%i-%s '), Date_format (@a, '%f ');
Query OK, 1 row Affected (0.00 sec)
records:1 duplicates:0 warnings:0
Mysql> select * from Mysql_microsecond;
+---------------------+-----------------+
| log_time_prefix | log_time_suffix
| +---------------------+-----------------+
| 2009-08-11 17:47:02 | 222009 |
+---------------------+-----------------+
1 row in Set (0.00 sec)
or use varchar to store all the time fields, or store a hash to ensure performance!
A lot of ways, it depends on your application how to use reasonable.