linux下mysql数据库自动建立分区脚本
上一篇 /
下一篇 2011-04-18 23:01:37
/ 个人分类:工作相关
需求:随着用户数量增加,每天的数据量增加,影响查找速度。用系统每天定时生产第二天的分区来将数据分块存储,这样myd.myi就不会很大。
系统:linux 通过
shell脚本实现为
数据库添加分区,自动实现每天一分区,自动建立下一天的分区
前提:数据库已建立分区,在当前目录建立名为sql的文本文件,用来存放输出的sql脚本。
脚本:
#!/bin/bash#获得当天时间
time1=`date --date='next day' +%Y%m%d`
#获得第二天的时间
time2=`date --date='2 day' +%Y%m%d`
echo -e "alter table T_PING_INFO add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);\n
alter table T_PRO_TJ add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);\n
alter table T_REPORT_INFO add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);\n
alter table T_USER_OP_INFO add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);\n
alter table T_WARN_INFO add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);\n
alter table T_PINGS_STATISTICS add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);\n
alter table T_TJ_STATISTICS add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);\n
alter table T_HTTP_STATISTICS add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);\n
alter table T_WEB_TJ_INFO add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);\n
alter table T_HTTP_INFO add partition (partition p$time1 values less than (to_days('$time2'))Engine=InnoDB);" >/root/sql_script
chmod 777 /root/sql_script
/data/bin/mysql -uroot -p123456 -Dtest</root/sql_script
注意问题:crond环境中的环境变量和脚本单独运行时的环境变量不一致,所以脚本中需要用绝对路径,否则会导致脚本单独运行成功,但是在crond环境下却没有执行。
收藏
举报
TAG: