删除某个表我知道是使用
DROP TABLE
这种命令,如果我只想删除以WP_
开头的表呢该怎么写SQL呢?
mysql的drop table不支持通配符,所以,你的需求没办法用一条SQL语句搞定,你有两个选择:
- 写一个UDF(用户自定义函数)来实现,先查某DB下面以wp_开头的表,再删除之
- 用bash shell,类似这样(语法包含错误,只是示意思路,请自行调试):
for table_name in `mysql -uroot -e 'use your_db; show tables' | grep wp_`
do
mysql -uroot -e 'use your_db; drop table $table_name if exists'
done
只能拼接SQL语句然后动态执行了。。。
set @str = (select concat('drop table ', group_concat(table_name separator ','),';')
from information_schema.tables
where table_schema = 'your_schema' and table_name like 'WP__%');
prepare stmt from @str;
execute stmt;
deallocate prepare stmt;
可以参考下 http://stackoverflow.com/questions/54…
正文完