MySql

Part 2

Posted by Dingding on September 22, 2017

show create table tablename

显示创建表时的create语句,可以用来查看表的注释

导出整个数据库结构和数据

mysqldump -h localhost -uroot -p123456 database > dump.sql

导出单个数据表结构和数据

mysqldump -h localhost -uroot -p123456 database table > dump.sql

导出整个数据库结构(不包含数据)

mysqldump -h localhost -uroot -p123456 -d database > dump.sql

导出单个数据表结构(不包含数据)

mysqldump -h localhost -uroot -p123456 -d database table > dump.sql

指定自增开始值

CREATE TABLE `forum_article_index` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `forum_id` bigint(20) unsigned NOT NULL DEFAULT '0',
  `modify_time` bigint(20) NOT NULL DEFAULT '0',
  `extra` varchar(256) DEFAULT NULL,

  PRIMARY KEY (`id`),
  KEY `idx_user_id_modify_time` (`user_id`,`modify_time`),
  KEY `idx_user_id_create_time` (`user_id`,`create_time`)
) ENGINE=InnoDB AUTO_INCREMENT=132449328 DEFAULT CHARSET=utf8mb4

按分钟对数据分组

SELECT count(*), FROM_UNIXTIME(add_time, '%Y-%m-%d %H:%i') as fmt_add_time 
from xm_order 
where add_time>1542113903-60*60 and add_time<1542113903 
group by fmt_add_time 
order by fmt_add_time;