要删除某个数据库下面所有表的方法:
方法一
比如删除test数据库下所有表,如果要删除某些前缀的表
比如删除test数据库下所有表,如果要删除某些前缀的表
-
mysql -uroot -h127.0.0.1 --skip-column-names -A -e "select concat('drop table test.', table_name,';') from information_schema.tables where table_schema = 'test'" > /tmp/tmp_drop.sql
- mysql -uroot -h127.0.0.1 test --show-warnings -v -v -v -e "source /tmp/tmp_drop.sql"
方法2
1 获取所有的表
-
#!/bin/sh
-
# auth yangyi
-
TAB_FILE=/home/admin/yangyi/fin_report.txt
-
gettab(){
-
mysql -uroot -h127.0.0.1 --skip-column-names $TAB_FILE
-
SELECT CONCAT("xxx.",table_name) FROM information_schema.tables
-
where information_schema.tables.table_schema='logcollector' and information_schema.tables.TABLE_NAME LIKE 'fingerprint_report_20%';
-
EOF
-
return $?
-
}
-
drop_tab(){
-
while read TAB
-
do
-
echo "drop table if exists $TAB;"
-
mysql -uroot -h127.0.0.1 -P3306 -Ne "drop table if exists $TAB;"
-
sleep 0.2
-
done $TAB_FILE
-
return $?
-
}
-
main(){
-
gettab && echo "gettab successed " || echo "gettab failed!!"
-
echo '===========start drop table at `date +%F` =========================='
-
drop_tab && echo "drop_tab successed" || echo "drop_tab failed"
-
echo '===========end drop table at `date +%F` =========================='
-
}
- main