通过Shell脚本删除指定MySQL数据库的非系统库的所有表和库
#!/bin/bash
dbs=`mysql -h127.0.0.1 -P3340 -uroot -proot -e "show databases \G" |grep "Database:"|grep -Ev " (information_schema|mysql|sys|performance_schema)"| awk '{print $2}'`
for db in $dbs
do
tables=`mysql -h127.0.0.1 -P3340 -uroot -proot -e "use $db;show tables \G" |grep "Tables_in_$db:"| awk '{print $2}'`
for table in $tables
do
mysql -h127.0.0.1 -P3340 -uroot -proot -e "drop table $db.$table;"
if [[ $? == 0 ]]
then
echo "delete table $db.$table"
fi
done
done