时间:2021-07-01 10:21:17 帮助过:18人阅读
我这里举一个简单的例子,来存储秒之前和之后的部分。
对于把时间字段作为主键的应用,我们可以建立以下的表来作相应的转化:
mysql> create table mysql_microsecond ( log_time_prefix timestamp not null default 0, log_time_suffix mediumint not null 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)
或者是用VARCHAR来存储所有的时间字段, 又或者是存储一个HASH来保证性能!
方法很多,就看你的应用怎么用合理了。