批量删除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_attachment;              |
| drop table forum_attachment_0;            |
| drop table forum_attachment_1;            |
| drop table forum_attachment_2;            |
| drop table forum_attachment_3;            |
| drop table forum_attachment_4;            |
| drop table forum_attachment_5;            |
| drop table forum_attachment_6;            |
| drop table forum_attachment_7;            |
| drop table forum_attachment_8;            |
| drop table forum_attachment_9;            |
| drop table forum_attachment_exif;         |
| drop table forum_attachment_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_imagetype;               |
| 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_image;        |
| 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_threadimage;             |
| 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_attachment;             |
| 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执行即可。

时间: 2024-08-02 06:55:32

批量删除mysql一个库所有数据表方法的相关文章

MySQL中快速复制数据表方法汇总

本文将着重介绍两个MySQL命令的组合,它将以原有数据表为基础,创建相同结构和数据的新数据表. 这可以帮助你在开发过程中快速的复制表格作为测试数据,而不必冒险直接操作正在运行 的数据表. 示例如下: 将 production 数据库中的 mytbl 表快速复制为 mytbl_new,2个命令如下: CREATE TABLE mytbl_new LIKE production.mytbl; INSERT mytbl_new SELECT * FROM production.mytbl; 第一个命令

批量删除指定数据库中的指定表

-- ---------------------------------------------------------------------------------------------------------- -- -- 1.查询:得到批量删除指定数据库中的指定表: -- 2.执行:将得到的结果复制下来,再重新执行: -- SELECT CONCAT( 'drop table ', table_name, '; ' ) FROM information_schema. TABLES W

MySQL基础学习之数据表

查看数据表 SHOW TABLE; 查看数据表详细结构 SHOW CREATE TABLE 表名\G; 创建数据表 CREATE TABLE 表名(数据名 类型,数据名1  类型2); CREATE TABLE department ( d_id INT(10) , d_name VARCHAR(20) , function VARCHAR(20) , address VARCHAR(30) ); 删除数据表 DROP TABLE 表名; 修改数据表 修改数据表名        ALTER TA

MySQL 一个库中表数量是否有限制?

在网上找了一下,有说几乎没有限制的,也有说表多了肯定会影响性能的,综合起来应该讲: 1)一个库中表数是有限制的, 按照 UNSIGNED 类型,最多42亿多一点,正常应用根本达不到. 2)文件系统对同时打开文件数有限制,一般 2048.虽可修改,但是设计表结构时,对于那些有可能需要同时打开的数据表还是不要拆分过细,否则影响性能那是肯定滴. 3)拆分过多最大的坏处,体现在:数据库的维护上面.因此要慎重分析自己的业务模型,数据增长趋势,技术实力等综合因素. MySQL 一个库中表数量是否有限制?

mysql更改已有数据表的字符集,保留原有数据内容

mysql更改已有数据表的字符集,保留原有数据内容     原文网址:http://blog.csdn.net/learn_2/article/details/6460370 环境:在应用开始阶段没有正确的设置字符集,在运行一段时间以后才发现存在不能满足需求需要调整,又不想丢弃这段时间的数据,那么就需要进行字符集的修改.字符集的修改不能直接通过"alter database character set *** " 或者 "alter table tablename chara

最简单删除SQL Server中所有数据的方法

原文:最简单删除SQL Server中所有数据的方法  最简单删除SQL Server中所有数据的方法 编写人:CC阿爸 2014-3-14 其实删除数据库中数据的方法并不复杂,为什么我还要多此一举呢,一是我这里介绍的是删除数据库的所有数据,因为数据之间可能形成相互约束关系,删除操作可能陷入死循环,二是这里使用了微软未正式公开的sp_MSForEachTable存储过程. 也许很多读者朋友都经历过这样的事情:要在开发数据库基础上清理一个空库,但由于对数据库结构缺乏整体了解,在删除一个表的记录时,

Mysql导入导出大量数据的方法、备份恢复办法

经常使用PHP+Mysql的朋友一般都是通过phpmyadmin来管理数据库的.日常的一些调试开发工作,使用phpmyadmin确实很方便.但是当我们需要导出几百兆甚至几个G的数据库时,phpmyadmin就会很卡.甚至如果你是想导入大量数据,则phpmyadmin完全无法完成.因为phpmyadmin是基于PHP网页的,无法上传太大的sql文件.其实mysql官方给了我们很好的解决方案:mysqldump. 下面介绍,如何在Windows环境下,使用mysqldump导出数据库: 找到你mys

如何通过PhpMyAdmin批量删除MYSQL数据库数据表

使用这个方法前,强烈建议先备份整个数据库.至于怎么备份?你不会么?在本文下方留言吧. 具体方法:复制下面的php执行语句,保存为sql.php文件(注意配置数据库名称.密码.数据表头),通过ftp上传到网站跟目录,运行. <?php //设置数据库连接信息.数据库服务器地址,数据库用户名,数据密码 mysql_connect('localhost','root','123456'); //设置查询的数据库名称,比如CMSYOU当前设置的是phpcms mysql_select_db('phpcm

Python批量删除mysql中千万级大量数据

场景描述 线上mysql数据库里面有张表保存有每天的统计结果,每天有1千多万条,这是我们意想不到的,统计结果咋有这么多.运维找过来,磁盘占了200G,最后问了运营,可以只保留最近3天的,前面的数据,只能删了.删,怎么删? 因为这是线上数据库,里面存放有很多其它数据表,如果直接删除这张表的数据,肯定不行,可能会对其它表有影响.尝试每次只删除一天的数据,还是卡顿的厉害,没办法,写个Python脚本批量删除吧. 具体思路是: 每次只删除一天的数据: 删除一天的数据,每次删除50000条: 一天的数据删