#!/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;
网友评论