mysql技巧杂烩 (二)
mysql技巧杂烩 (二) 1. 日期与时间 a.若只存日期,则使用"date"类型;若只存时间,则使用"time"类型; 若要存日期+时间,则使用datetime类型(用timestamp也可以,但稍微复杂一些) a2.mysql的日期时间最多精确到“秒”级别 b.string -> date: select str_to_date(‘2012-02-28 18:23:30’, ‘%Y-%m-%d %T’); c. date -> string: select date_format(now(), ‘%Y-%m-%d %T’); d. mysql还提供了很多强大的日期计算函数,此处不述 2. 元数据 a.查看元数据有两大工具:使用SHOW命令 或者 查询INFORMATION_SCHEMA库里的表 b.显示所有数据库:select schema_name from information_schema.schemata; 或 show databases; c.显示库里所有的表: select table_name from information_schema.tables where table_schema=’cookbook’; 或 show tables; d.显示表里所有的字段: i. select * from information_schema.columns where table_schema=’cookbook’ …