【MySQL】批量删除mysql中数据库中的表

要删除某个数据库下面所有表的方法:
方法一
比如删除test数据库下所有表,如果要删除某些前缀的表
  1. 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
  2. mysql -uroot -h127.0.0.1 test --show-warnings -v -v -v -e "source /tmp/tmp_drop.sql"
方法2
1 获取所有的表

  1. #!/bin/sh
  2. # auth yangyi
  3. TAB_FILE=/home/admin/yangyi/fin_report.txt
  4. gettab(){
  5. mysql -uroot -h127.0.0.1 --skip-column-names < $TAB_FILE
  6. SELECT CONCAT("xxx.",table_name) FROM information_schema.tables
  7.  where information_schema.tables.table_schema='logcollector' and information_schema.tables.TABLE_NAME LIKE 'fingerprint_report_20%';
  8. EOF
  9. return $?
  10. }
  11. drop_tab(){
  12. while read TAB
  13. do
  14.  echo "drop table if exists $TAB;"
  15.  mysql -uroot -h127.0.0.1 -P3306 -Ne "drop table if exists $TAB;"
  16.  sleep 0.2
  17. done < $TAB_FILE
  18. return $?
  19. }
  20. main(){
  21. gettab && echo "gettab successed " || echo "gettab failed!!"
  22. echo '===========start drop table at `date +%F` =========================='
  23. drop_tab && echo "drop_tab successed" || echo "drop_tab failed"
  24. echo '===========end drop table at `date +%F` =========================='
  25. }
  26. main


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22664653/viewspace-742395/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22664653/viewspace-742395/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值