生成清除某个数据库下的所有表的SQL语句

方法1:重建库和表
用mysqldump --no-data把建表SQL导出来,然后drop database再create database,执行一下导出的SQL文件;

方法2:生成清空所有表的SQL
select CONCAT('TRUNCATE TABLE ',table_name,';') from information_schema.tables where TABLE_SCHEMA = 'db1'
导出到文件
select CONCAT('TRUNCATE TABLE ',table_name,';') into outfile '/website/truncatetable.sql' from information_schema.tables where TABLE_SCHEMA = 'db1'
 
 
SELECT concat('DROP TABLE IF EXISTS ', table_name, ';')
FROM information_schema.tables
WHERE table_schema = 'mydb';

mydb换成你想删除的数据库的名字
这样可以生成一个批量处理的sql语句,你需要再运行一次这个结果集
就可以删除所有的表而不删除数据库了
 
 
原文地址:https://www.cnblogs.com/lzh007blog/p/9272522.html