如何在没有 DROP 数据库权限的情况下从命令行删除所有 MySQL 表? [英] How to remove all MySQL tables from the command-line without DROP database permissions?

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

问题描述

如何使用命令提示符删除 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; 

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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆