MySQL 如何删除MySQL数据库中的所有表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4723625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete all the tables in a MySQL database?
提问by deepa
Possible Duplicate:
Truncate all tables in a MySQL database in one command?
可能的重复:
在一个命令中截断 MySQL 数据库中的所有表?
I need to delete, or drop, all the tables in a MySQL database with single command without knowing the tablenames. Is this possible?
我需要在不知道表名的情况下使用单个命令删除或删除 MySQL 数据库中的所有表。这可能吗?
回答by ajreal
drop database YOUR_DATABASE;
/* this will delete all the tables for this database */
create database YOUR_DATABASE;
/* added back the database namespace */
回答by Suthagaran
Rather long, but try this command (after replacing the obvious things):
相当长,但试试这个命令(替换明显的东西后):
mysql --user=YOUR_USERNAME --password=YOUR_PASSWORD -BNe "show tables" YOUR_DBSCHEMA_NAME | tr '\n' ',' | sed -e 's/,$//' | awk '{print "SET FOREIGN_KEY_CHECKS = 0;DROP TABLE IF EXISTS " ";SET FOREIGN_KEY_CHECKS = 1;"}' | mysql --user=YOUR_USERNAME --password=YOUR_PASSWORD YOUR_DBSCHEMA_NAME