- #!/bin/sh
- mysql_user=root
- mysql_pass=123123
- time_log=/opt/time
- databases=/opt/databases
- /usr/bin/mysql -u$mysql_user -p$mysql_pass -e "show databases" | grep -v "Database" > /opt/databases
- sed -i "s/information_schema//" $databases
- sed -i "s/mysql//" $databases
- sed -i "s/test//" $databases
- databases1=$(cat /opt/databases)
- for i in $databases1
- do
- echo "database $i starting"
- tables=$(/usr/bin/mysql $i -u$mysql_user -p$mysql_pass -e "show tables" | grep -v "Tables" > /opt/$i)
- tablelist=$(cat /opt/$i)
- echo "optimize database $i starting" >> $time_log
- echo "$i start at $(date +[%Y/%m/%d/%H:%M:%S])" >> $time_log
- for list in $tablelist
- do
- echo $list
- /usr/bin/mysql $i -u$mysql_user -p$mysql_pass -e "optimize table $list"
- done
- echo "$i end at $(date +[%Y/%m/%d/%H:%M:%S])" >> $time_log
- echo >> $time_log
- done
本文转自 ppabc 51CTO博客,原文链接:http://blog.51cto.com/ppabc/742681