数据库创建脚本

#!/bin/bash

user="ronly"

pass="12345678"

DB_name="logdb"

#create table

create_table_sql(){

mysql -u${user} -p${pass} ${DB_name} -e "CREATE TABLE ${Table_name} (

  id int(11) NOT NULL AUTO_INCREMENT COMMENT '日志主键ID',

  userid int(11) NOT NULL DEFAULT '0' COMMENT '用户的游戏ID',

  accountid varchar(50) NOT NULL DEFAULT '' COMMENT '用户绑定的微信openid',

  liushui bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '用户的流水数据',

  liushui_type tinyint(2) NOT NULL DEFAULT '0' COMMENT '流水的输赢,0、表示未知,1、表示赢,2、表示输',

  youxi_type int(11) NOT NULL DEFAULT '0' COMMENT '用户玩的什么游戏,0、表示未知',

  channel_id int(11) NOT NULL DEFAULT '0' COMMENT '用户的渠道标识,0表示未知',

  created int(11) NOT NULL DEFAULT '0' COMMENT '日志的产生时间',

  PRIMARY KEY (id),

  KEY userid (userid),

  KEY accountid (accountid),

  KEY channel_id (channel_id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"

}

#Compared Table

Comparedtable(){

mysql -N -s -u${user} -p${pass} -e "select count(*) from information_schema.tables where table_schema='${DB_name}' and table_name='${Table_name}';"

}

#create action

for((i=0;i<=7;i++));do

        Day=$(date -d +"$i"day +%Y_%m_%d)

        Table_name=logs_"${Day}"

if [ $(Comparedtable) -eq 0 ]; then

    echo "The table Created ${Table_name}"

                create_table_sql

  else

    echo "The table ${Table_name} is already exists"

fi

done;

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容