2020-08-15 批量建表&批量删表

1.通过shell脚本批量建表

#!/bin/bash
#批量新建数据表
for y in {1..53};do
 mysql -uroot  -pTimevale123 -P3306  -e "use seal; create table seal_sign_log_2020_$y(
id bigint(64) unsigned NOT NULL COMMENT 'id',
  doc_name varchar(512) NOT NULL DEFAULT '' COMMENT '文档名称',
  seal_code varchar(32) NOT NULL DEFAULT '' COMMENT '印章编码',
  sign_log_id varchar(64) NOT NULL DEFAULT '' COMMENT '签署日志id',
  account_id bigint(11) DEFAULT NULL COMMENT '用户id',
  account_unique_id varchar(50) DEFAULT NULL COMMENT '用户唯一标识',
  account_name varchar(100) DEFAULT NULL COMMENT '姓名',
  organize_id bigint(11) DEFAULT NULL COMMENT '组织机构id',
  organize_full_name varchar(100) DEFAULT NULL COMMENT '组织机构全称',
  sign_time datetime DEFAULT NULL COMMENT '签署时间',
  sign_type int(2) DEFAULT NULL COMMENT '签署类型:1-PDF签署,2-OFD签署',
  sign_mac varchar(64) NOT NULL DEFAULT '' COMMENT '签署设备mac',
  sign_ip varchar(15) DEFAULT NULL COMMENT '签署IP地址',
  create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  sign_task_id varchar(36) DEFAULT NULL COMMENT '签署任务id',
  auth_way int(2) NOT NULL DEFAULT '0' COMMENT '意愿认证方式,1:ukey意愿认证 2:后台静默授权',
  project_name varchar(100) DEFAULT '' COMMENT '项目名称',
  PRIMARY KEY (id) USING BTREE,
  KEY idx_create_time (create_time) USING BTREE,
  KEY idx_sign_time (sign_time) USING BTREE,
  KEY idx_unique_id (account_unique_id) USING BTREE,
  KEY idx_account_name (account_name) USING BTREE,
  KEY idx_organize_full_name (organize_full_name) USING BTREE,
  KEY idx_sign_type (sign_type) USING BTREE,
  KEY index_sign_task_id (sign_task_id) USING BTREE,
  KEY idx_project_name (project_name),
  KEY idx_org_id_seal_code (seal_code,organize_id),
  KEY idx_project_test (project_name,seal_code)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='签章日志';"
done

2.批量删表

使用

Select CONCAT( 'drop table ', table_name, ';' ) FROM information_schema.tables Where table_name LIKE 'seal_sign_log_%';

可生成drop表语句,然后可以批量删除:

drop table seal_sign_log_2020_1 ...;

你可能感兴趣的:(2020-08-15 批量建表&批量删表)