我的编程空间,编程开发者的网络收藏夹
学习永远不晚

批量删除mysql一个库所有数据表方法

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

批量删除mysql一个库所有数据表方法

批量删除mysql一个库所有数据表方法


删除表的命令

drop table 表名;

如果有100张表,手工执行100次,想想就崩溃。

下面提供一个使用information_schema库的方案来批量删除数据表:
SELECT CONCAT('drop table ',table_name,';') FROM information_schema.`TABLES` WHERE table_schema='数据库名';

如通过这条命令来得到drop table 表名;这样的语句,然后批量执行。
mysql> SELECT CONCAT('drop table ',table_name,';') FROM information_schema.`TABLES` WHERE table_schema='discuz';
+-------------------------------------------+
| CONCAT('drop table ',table_name,';')      |
+-------------------------------------------+
| drop table common_admincp_cmenu;          |
| drop table common_admincp_group;          |
| drop table common_admincp_member;         |
| drop table common_admincp_perm;           |
| drop table common_admincp_session;        |
| drop table common_admingroup;             |
| drop table common_adminnote;              |
| drop table common_advertisement;          |
| drop table common_advertisement_custom;   |
| drop table common_banned;                 |
| drop table common_block;                  |
| drop table common_block_favorite;         |
| drop table common_block_item;             |
| drop table common_block_item_data;        |
| drop table common_block_permission;       |
| drop table common_block_pic;              |
| drop table common_block_style;            |
| drop table common_block_xml;              |
| drop table common_cache;                  |
| drop table common_card;                   |
| drop table common_card_log;               |
| drop table common_card_type;              |
| drop table common_connect_guest;          |
| drop table common_credit_log;             |
| drop table common_credit_log_field;       |
| drop table common_credit_rule;            |
| drop table common_credit_rule_log;        |
| drop table common_credit_rule_log_field;  |
| drop table common_cron;                   |
| drop table common_devicetoken;            |
| drop table common_district;               |
| drop table common_diy_data;               |
| drop table common_domain;                 |
| drop table common_failedip;               |
| drop table common_failedlogin;            |
| drop table common_friendlink;             |
| drop table common_grouppm;                |
| drop table common_invite;                 |
| drop table common_magic;                  |
| drop table common_magiclog;               |
| drop table common_mailcron;               |
| drop table common_mailqueue;              |
| drop table common_member;                 |
| drop table common_member_action_log;      |
| drop table common_member_connect;         |
| drop table common_member_count;           |
| drop table common_member_crime;           |
| drop table common_member_field_forum;     |
| drop table common_member_field_home;      |
| drop table common_member_forum_buylog;    |
| drop table common_member_grouppm;         |
| drop table common_member_log;             |
| drop table common_member_magic;           |
| drop table common_member_medal;           |
| drop table common_member_newprompt;       |
| drop table common_member_profile;         |
| drop table common_member_profile_setting; |
| drop table common_member_security;        |
| drop table common_member_secwhite;        |
| drop table common_member_stat_field;      |
| drop table common_member_status;          |
| drop table common_member_validate;        |
| drop table common_member_verify;          |
| drop table common_member_verify_info;     |
| drop table common_member_wechat;          |
| drop table common_member_wechatmp;        |
| drop table common_myapp;                  |
| drop table common_myinvite;               |
| drop table common_mytask;                 |
| drop table common_nav;                    |
| drop table common_onlinetime;             |
| drop table common_optimizer;              |
| drop table common_patch;                  |
| drop table common_plugin;                 |
| drop table common_pluginvar;              |
| drop table common_process;                |
| drop table common_regip;                  |
| drop table common_relatedlink;            |
| drop table common_remote_port;            |
| drop table common_report;                 |
| drop table common_searchindex;            |
| drop table common_seccheck;               |
| drop table common_secquestion;            |
| drop table common_session;                |
| drop table common_setting;                |
| drop table common_smiley;                 |
| drop table common_sphinxcounter;          |
| drop table common_stat;                   |
| drop table common_statuser;               |
| drop table common_style;                  |
| drop table common_stylevar;               |
| drop table common_syscache;               |
| drop table common_tag;                    |
| drop table common_tagitem;                |
| drop table common_task;                   |
| drop table common_taskvar;                |
| drop table common_template;               |
| drop table common_template_block;         |
| drop table common_template_permission;    |
| drop table common_uin_black;              |
| drop table common_usergroup;              |
| drop table common_usergroup_field;        |
| drop table common_visit;                  |
| drop table common_word;                   |
| drop table common_word_type;              |
| drop table connect_disktask;              |
| drop table connect_feedlog;               |
| drop table connect_memberbindlog;         |
| drop table connect_postfeedlog;           |
| drop table connect_tthreadlog;            |
| drop table forum_access;                  |
| drop table forum_activity;                |
| drop table forum_activityapply;           |
| drop table forum_announcement;            |
| drop table forum_p_w_upload;              |
| drop table forum_p_w_upload_0;            |
| drop table forum_p_w_upload_1;            |
| drop table forum_p_w_upload_2;            |
| drop table forum_p_w_upload_3;            |
| drop table forum_p_w_upload_4;            |
| drop table forum_p_w_upload_5;            |
| drop table forum_p_w_upload_6;            |
| drop table forum_p_w_upload_7;            |
| drop table forum_p_w_upload_8;            |
| drop table forum_p_w_upload_9;            |
| drop table forum_p_w_upload_exif;         |
| drop table forum_p_w_upload_unused;       |
| drop table forum_attachtype;              |
| drop table forum_bbcode;                  |
| drop table forum_collection;              |
| drop table forum_collectioncomment;       |
| drop table forum_collectionfollow;        |
| drop table forum_collectioninvite;        |
| drop table forum_collectionrelated;       |
| drop table forum_collectionteamworker;    |
| drop table forum_collectionthread;        |
| drop table forum_creditslog;              |
| drop table forum_debate;                  |
| drop table forum_debatepost;              |
| drop table forum_faq;                     |
| drop table forum_filter_post;             |
| drop table forum_forum;                   |
| drop table forum_forum_threadtable;       |
| drop table forum_forumfield;              |
| drop table forum_forumrecommend;          |
| drop table forum_groupcreditslog;         |
| drop table forum_groupfield;              |
| drop table forum_groupinvite;             |
| drop table forum_grouplevel;              |
| drop table forum_groupuser;               |
| drop table forum_hotreply_member;         |
| drop table forum_hotreply_number;         |
| drop table forum_p_w_picpathtype;               |
| drop table forum_medal;                   |
| drop table forum_medallog;                |
| drop table forum_memberrecommend;         |
| drop table forum_moderator;               |
| drop table forum_modwork;                 |
| drop table forum_newthread;               |
| drop table forum_onlinelist;              |
| drop table forum_order;                   |
| drop table forum_poll;                    |
| drop table forum_polloption;              |
| drop table forum_polloption_p_w_picpath;        |
| drop table forum_pollvoter;               |
| drop table forum_post;                    |
| drop table forum_post_location;           |
| drop table forum_post_moderate;           |
| drop table forum_post_tableid;            |
| drop table forum_postcache;               |
| drop table forum_postcomment;             |
| drop table forum_postlog;                 |
| drop table forum_poststick;               |
| drop table forum_promotion;               |
| drop table forum_ratelog;                 |
| drop table forum_relatedthread;           |
| drop table forum_replycredit;             |
| drop table forum_rsscache;                |
| drop table forum_sofa;                    |
| drop table forum_spacecache;              |
| drop table forum_statlog;                 |
| drop table forum_thread;                  |
| drop table forum_thread_moderate;         |
| drop table forum_threadaddviews;          |
| drop table forum_threadcalendar;          |
| drop table forum_threadclass;             |
| drop table forum_threadclosed;            |
| drop table forum_threaddisablepos;        |
| drop table forum_threadhidelog;           |
| drop table forum_threadhot;               |
| drop table forum_threadp_w_picpath;             |
| drop table forum_threadlog;               |
| drop table forum_threadmod;               |
| drop table forum_threadpartake;           |
| drop table forum_threadpreview;           |
| drop table forum_threadprofile;           |
| drop table forum_threadprofile_group;     |
| drop table forum_threadrush;              |
| drop table forum_threadtype;              |
| drop table forum_trade;                   |
| drop table forum_tradecomment;            |
| drop table forum_tradelog;                |
| drop table forum_typeoption;              |
| drop table forum_typeoptionvar;           |
| drop table forum_typevar;                 |
| drop table forum_warning;                 |
| drop table home_album;                    |
| drop table home_album_category;           |
| drop table home_appcreditlog;             |
| drop table home_blacklist;                |
| drop table home_blog;                     |
| drop table home_blog_category;            |
| drop table home_blog_moderate;            |
| drop table home_blogfield;                |
| drop table home_class;                    |
| drop table home_click;                    |
| drop table home_clickuser;                |
| drop table home_comment;                  |
| drop table home_comment_moderate;         |
| drop table home_docomment;                |
| drop table home_doing;                    |
| drop table home_doing_moderate;           |
| drop table home_favorite;                 |
| drop table home_feed;                     |
| drop table home_feed_app;                 |
| drop table home_follow;                   |
| drop table home_follow_feed;              |
| drop table home_follow_feed_archiver;     |
| drop table home_friend;                   |
| drop table home_friend_request;           |
| drop table home_friendlog;                |
| drop table home_notification;             |
| drop table home_pic;                      |
| drop table home_pic_moderate;             |
| drop table home_picfield;                 |
| drop table home_poke;                     |
| drop table home_pokearchive;              |
| drop table home_share;                    |
| drop table home_share_moderate;           |
| drop table home_show;                     |
| drop table home_specialuser;              |
| drop table home_userapp;                  |
| drop table home_userappfield;             |
| drop table home_visitor;                  |
| drop table mobile_setting;                |
| drop table mobile_wechat_authcode;        |
| drop table mobile_wechat_masssend;        |
| drop table mobile_wechat_resource;        |
| drop table mobile_wsq_threadlist;         |
| drop table portal_article_content;        |
| drop table portal_article_count;          |
| drop table portal_article_moderate;       |
| drop table portal_article_related;        |
| drop table portal_article_title;          |
| drop table portal_article_trash;          |
| drop table portal_p_w_upload;             |
| drop table portal_category;               |
| drop table portal_category_permission;    |
| drop table portal_comment;                |
| drop table portal_comment_moderate;       |
| drop table portal_rsscache;               |
| drop table portal_topic;                  |
| drop table portal_topic_pic;              |
| drop table security_evilpost;             |
| drop table security_eviluser;             |
| drop table security_failedlog;            |
| drop table ucenter_admins;                |
| drop table ucenter_applications;          |
| drop table ucenter_badwords;              |
| drop table ucenter_domains;               |
| drop table ucenter_failedlogins;          |
| drop table ucenter_feeds;                 |
| drop table ucenter_friends;               |
| drop table ucenter_mailqueue;             |
| drop table ucenter_memberfields;          |
| drop table ucenter_members;               |
| drop table ucenter_mergemembers;          |
| drop table ucenter_newpm;                 |
| drop table ucenter_notelist;              |
| drop table ucenter_pm_indexes;            |
| drop table ucenter_pm_lists;              |
| drop table ucenter_pm_members;            |
| drop table ucenter_pm_messages_0;         |
| drop table ucenter_pm_messages_1;         |
| drop table ucenter_pm_messages_2;         |
| drop table ucenter_pm_messages_3;         |
| drop table ucenter_pm_messages_4;         |
| drop table ucenter_pm_messages_5;         |
| drop table ucenter_pm_messages_6;         |
| drop table ucenter_pm_messages_7;         |
| drop table ucenter_pm_messages_8;         |
| drop table ucenter_pm_messages_9;         |
| drop table ucenter_protectedmembers;      |
| drop table ucenter_settings;              |
| drop table ucenter_sqlcache;              |
| drop table ucenter_tags;                  |
| drop table ucenter_vars;                  |
+-------------------------------------------+
297 rows in set (0.02 sec)

mysql>

复制删除表命令出来,替换了|复制到mysql执行即可。

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

批量删除mysql一个库所有数据表方法

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

mysql 大表批量删除大量数据的实现方法

问题参考自:https://www.zhihu.com/question/440066129/answer/1685329456 ,mysql中,一张表里有3亿数据,未分表,其中一个字段是企业类型,企业类型是一般企业和个体户,个体户的数据量
2022-05-11

mysql中批量删除数据的方法

mysql中批量删除数据的方法?这个问题可能是我们日常学习或工作经常见到的。希望通过这个问题能让你收获颇深。下面是小编给大家带来的参考内容,让我们一起来看看吧!mysql中批量删除数据的方法:首先找出符合条件的最大id;然后在where字段
2022-11-30

mysql删除库中所有表的方法是什么

要删除 MySQL 数据库中的所有表,可以通过以下步骤来实现:登录到 MySQL 数据库:使用适当的工具(如命令行、phpMyAdmin 等)登录到您的 MySQL 数据库。选择要操作的数据库:在删除数据库中的所有表之前,请确保已经选择了
mysql删除库中所有表的方法是什么
2024-04-09

mysql批量删除数据方法及注意事项说明

目录一、批量删除编程网数据的三种常见方法1、DROP TABLE2、TRUNCATE TABLE3、DELETE FROM table二、TRUNCATE 和 DELETE 的相同之处三、TRUNCATE 和 DELETE 的差异1、事务回
mysql批量删除数据方法及注意事项说明
2024-01-29

Python增量循环删除MySQL表数据的方法

需求场景:有一业务数据库,使用MySQL 5.5版本,每天会写入大量数据,需要不定期将多表中“指定时期前“的数据进行删除,在SQL SERVER中很容易实现,写几个WHILE循环就搞定,虽然MySQL中也存在类似功能,怎奈自己不精通,于是采
2022-06-04

mysql如何将数据库中的所有表结构和数据导入到另一个库

目编程录一、问题描述二http://www.lsjlt.com、解决方案1.使用mysqldump命令备份数据库2.创建目标数据库3.导入数据 到目标数据库三、补充知识3.1 mysqldump命令介绍3.2 常用备份命令总结一、问题描述
mysql如何将数据库中的所有表结构和数据导入到另一个库
2024-10-11

mysql 将数据库中的所有表结构和数据 导入到另一个库(亲测有效)

一、问题描述 在本地开发一个功能,需要结合具体数据测试代码是否正确,但服务器上的数据不可随便修改。此时则需要将服务器上某个数据库的表批量导入到本地、而后进行测试。将数据库db1中的所有表及数据(如table1、table2),批量导入到另一
mysql 将数据库中的所有表结构和数据 导入到另一个库(亲测有效)
2023-12-22

MySQL用truncate命令快速清空一个数据库中的所有表

1. 先执行select语句生成所有truncate语句 语句格式: select CONCAT('truncate TABLE ',table_schema,'.',TABLE_NAME, ';') from INFORMATION_SC
2022-05-25

MySQL:想实现sql语句进行批量删除数据库或表,而引发的熬夜探究

因为在自测过程中,创建了很多数据库,一个个手动删除属实有点对不起程序员这个身份,那么有没有简单的sql语句操作来进行批量删除数据库呢?于是便有了本篇文章 上面图片是AI创作,未经允许,不可商用哦! 目录 前情提示思路实操批量
2023-08-19

编程热搜

目录