时间:2021-07-01 10:21:17 帮助过:59人阅读
base="xxa.rds.aliyuncs.com"
express="xxb.mysql.rds.aliyuncs.com"
log="xxc.rds.aliyuncs.com"
#上一个月
before_mon=`date -d "-1 month" +"%m"`
#下一个月
next_mon=`date -d "+1 month" +"%m"`
#上一个月,去掉月前面的0
before_mv_mon=`date -d "-1 month" +"%-m"`
#下一个月,去掉月前面的0
next_mv_mon=`date -d "+1 month" +"%-m"`
#前一个月的年份
year=`date +%Y`
#下一个月的年份
year_next=`date -d "+1 month" +"%Y"`
/usr/local/mysql/bin/mysql -u xxuser -pxxpass -h $base -e "use kd_shop;CREATE TABLE tbl_scan_to_e3_bak_"$year_next"_$next_mv_mon like tbl_scan_to_e3_bak_"$year"_$before_mv_mon;"
sleep 1
/usr/local/mysql/bin/mysql -u xxuser -pxxpass -h $base -e "use kd_shop;CREATE TABLE tbl_scan_to_qf_bak_"$year_next"_$next_mv_mon like tbl_scan_to_qf_bak_"$year"_$before_mv_mon;"
sleep 1
/usr/local/mysql/bin/mysql -u xxuser -pxxpass -h $base -e "use sms;CREATE TABLE tbl_sms_history_"$year_next"$next_mon like tbl_sms_history_"$year"$before_mon;"
sleep 1
/usr/local/mysql/bin/mysql -u xxuser -pxxpass -h $log -e "use dts;CREATE TABLE dts_message_history_"$year_next"$next_mon like dts_message_history_"$year"$before_mon;"
设置权限
chmod 755 create_tables.sh
设置任务计划,每天跑一遍,防止未创建
01 23 * * * /opt/create_tables.sh
本文出自 “陨落星空” 博客,请务必保留此出处http://xiao987334176.blog.51cto.com/2202382/1681867
shell自动创建mysql数据表
标签:shell 自动创建 mysql表