参数列表:
[db] [db_host] [db_user] [db_passwd]
#! /bin/bash
if [ $1 ]
then
echo database $1;
else
echo 'backup database tables to gzip files sh bak_db_table.sh db [db_host] [db_user] [db_passwd]'; exit;
fi
[ $1 ] && db=$1
[ $2 ] && dbh=$2
[ $3 ] && dbu=$3
[ $4 ] && dbp=$4
[ $dbh ] && dbh="-h"$dbh
[ $dbu ] && dbu="-u"$dbu
[ $dbp ] && dbp="-p"$dbp
list=(`echo show tables|/opt/modules/mysql/bin/mysql $dbh $dbu $dbp $db`)
tbcount=$((${#list[@]}-2))
if [ $tbcount= -2 ] # Hg9{1+2;4fTZ ;_J}>]?bA,=SJ'0/
then
echo empty tables in $db or connent failed! ; exit 1;
fi
echo table count: $tbcount
for (( i = 1 ; i < ($tbcount+1) ; i ++ ))
do
table=${list[$i]}
echo alter table $db.$table
echo "alter table $db.$table type=MyISAM;"|/opt/modules/mysql/bin/mysql $dbh $dbu $dbp;
#sleep 10
done