表结构:CREATE TABLE `id` (
     `id` timestamp NOT NULL 
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8mysql> select * from id;
+---------------------+
| id                  |
+---------------------+
| 2013-01-10 20:21:04 |
+---------------------+
1 row in set (0.00 sec)timestamp存储的到底是时间戳还是datetime类似格式的字符串啊?
如果是时间戳,为什么select出来的不是时间戳呢?
如果是datetime类似的字符串,为什么datetime 8字节,而timestamp才四字节?谢谢各位指教.

解决方案 »

  1.   

    MySQL中的datetime与timestamp比较相同显示TIMESTAMP列的显示格式与DATETIME列相同。换句话说,显示宽度固定在19字符,并且格式为YYYY-MM-DD HH:MM:SS。不同范围datetime 以'YYYY-MM-DD HH:MM:SS'格式检索和显示DATETIME值。支持的范围为'1000-01-01 00:00:00'到'9999-12-31 23:59:59'TIMESTAMP值不能早于1970或晚于2037储存TIMESTAMP1.4个字节储存(Time stamp value is stored in 4 bytes)2.值以UTC格式保存( it stores the number of milliseconds)3.时区转化 ,存储时对当前的时区进行转换,检索时再转换回当前的时区。datetime1.8个字节储存(8 bytes storage)2.实际格式储存(Just stores what you have stored and retrieves the same thing which you have stored.)3.与时区无关(It has nothing to deal with the TIMEZONE and Conversion.)