技术开发 频道

MySQL-数据类型存储-TIMESTAMP

  下面来看一下存储的值:

  set @@time_zone = '+8:00';

  drop table if exists heyf;

  create table heyf (id int ,curtime timestamp) type myisam;

  insert into heyf values (11,'2008-05-09 15:09:48');

  system hexdump /opt/mysql/data/test/heyf.MYD

  ------------------------------------

  0000000 0bfd 0000 bc00 23f8 0048

  0000009

  ------------------------------------

  其中:

  -------------------------------

  fd : 标志位

  0b 00 00 00 : COL1 ,INT = 11

  bc f8 23 48 : 即时间.由于是反向存储,所以需要反向读取: 48 23 f8 bc

  -------------------------------

  反向读取过程:

  1) bc f8 23 48 --> 4823f8bc

  2) select '1970-01-01 00:00:00' + interval conv("4823f8bc",16,10) second ;

  -->2008-05-09 07:09:48

  3) select select @@time_zone;

  --> +08:00

  select '2008-05-09 07:09:48' + interval 8 hour ;

  --> 2008-05-09 15:09:48

  结果完全一致.

0
相关文章