MySQL 如何删除MySQL中的所有表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2189315/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:11:23  来源:igfitidea点击:

How to drop all table in MySQL?

mysqlphpmyadminmysql-management

提问by user198729

I don't want to drop database,

我不想删除数据库,

because I'm not hosting the website on my own machine,

因为我没有在自己的机器上托管网站,

drop the database will require create it again,and many settings.

删除数据库将需要再次创建它,以及许多设置。

Is there a command in MySQL that can be used to delete all tables in a specific database?

MySQL中是否有一个命令可以用来删除特定数据库中的所有表?

EDIT

编辑

Everything I can do is within a phpMyAdmin

我能做的一切都在phpMyAdmin 中

采纳答案by Suraj Chandran

mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP | mysql -u[USERNAME] -p[PASSWORD] [DATABASE]

mysqldump -u[用户名] -p[密码] --add-drop-table --no-data [数据库] | grep ^DROP | mysql -u[用户名] -p[密码] [数据库]

Herethere are more methods to drop all tables without dropping the database.

这里有更多方法可以删除所有表而不删除数据库。

回答by mkly

You were talking about doing this in phpMyAdmin.

您正在谈论在 phpMyAdmin 中执行此操作。

I just had to do this and I'm not sure what version you are using but in the version I have if you scroll to the bottom of the table list you can click "Check All" and then in the drop down next to it that has "With Selected:" you can select "Drop" and it empties all the tables.

我只需要这样做,我不确定您使用的是哪个版本,但在我拥有的版本中,如果您滚动到表格列表的底部,您可以单击“全部检查”,然后在它旁边的下拉菜单中有“With Selected:”你可以选择“Drop”,它会清空所有的表。

回答by Warnaud

You can also generate a sql file from the information_schema database:

也可以从 information_schema 数据库生成 sql 文件:

Select concat('DROP TABLE database_name.', table_name,';') from information_schema.TABLES where table_schema='database_name';

This will give an output like:

这将给出如下输出:

DROP TABLE database_name.table1;
DROP TABLE database_name.table2;
[...]
DROP TABLE database_name.tableN;

回答by codaddict

I'm not aware of anything direct to suit your needs. You might try doing the following:

我不知道有什么可以直接满足您的需求。您可以尝试执行以下操作:

Run this to show your drop commands:

运行此命令以显示您的放置命令:

mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | 
grep ^DROP


Nex you can do this to actually execute the drop commands:


Nex 你可以这样做来实际执行 drop 命令:

mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | 
grep ^DROP | 
mysql -u[USERNAME] -p[PASSWORD] [DATABASE]

回答by Leonard Daniel Bratosin

$q=mysql_query("SHOW TABLES FROM ".SQL_DATABASE_NAME);

while($r=mysql_fetch_assoc($q)){
    mysql_query("DROP TABLE ".$r["Tables_in_".SQL_DATABASE_NAME]); 
}

it work for me!

它对我有用!