mysql修行练级之特定日期数据表清理


mysql数据清理

dbname:mytest

表特征:my_table_test_20140701


#!/bin/sh

dbname="mytest"


for month in ` seq -f %02g 1 7`;do
mysql -h"$ip" -u -p $dbname -s -e "show tables like '%2014${month}%';" >tablelist_${month}.txt

sed  -i '/Tables_in_mytest/d' /data/tablelist_*.txt ;#mytest 为dbname


for tablename in `cat /data/tablelist_*.txt`
do
mysql -h"$ip" -u -p $dbname -s -e  \
"
drop table $tablename;
"
done



或:


#!/bin/bash

 

source /etc/profile

dbname=mytest 

echo show tables in ${dbname}|mysql -h $ip -uroot -p himytest -P3308 |grep $(date -d "100 days ago" +%Y%m%d )>./tables_clean_in_$dbname.txt

 

if [ -s ./tables_clean_in_$dbname.txt  ];then

 

for table_name in `cat ./tables_clean_in_$dbname.txt`;do echo drop table $table_name|mysql -h $ip -uroot -p himytest -P3308  -D ${dbname} ;done

 

else

echo "no tables need clean"

fi



你可能感兴趣的:(mysql,数据表清理)