本文介绍了如何从命令行删除所有MySQL表,没有DROP数据库权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用命令提示符删除Windows MySQL中的所有表?我想这样做的原因是我们的用户可以访问数据库删除,但没有访问重新创建数据库本身,因此我们必须手动删除表。有办法立刻删除所有的表吗?请记住,大多数表与外键链接,因此必须按特定顺序删除。

How do I drop all tables in Windows MySQL, using command prompt? The reason I want to do this is that our user has access to the database drops, but no access to re-creating the database itself, for this reason we must drop the tables manually. Is there a way to drop all the tables at once? Bear in mind that most of the tables are linked with foreign keys so they would have to be dropped in a specific order.

推荐答案

你可以这样生成语句: DROP TABLE t1,t2,t3,... 然后使用预备语句执行它:

You can generate statement like this: DROP TABLE t1, t2, t3, ... and then use prepared statements to execute it:

SET FOREIGN_KEY_CHECKS = 0; 
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables
  FROM information_schema.tables 
  WHERE table_schema = 'database_name'; -- specify DB name here.

SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1; 

这篇关于如何从命令行删除所有MySQL表,没有DROP数据库权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:00