生成清除某个数据库下的全部表的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语句,你须要再运行一次这个结果集 就能够删除全部的表而不删除数据库了
相关文章
相关标签/搜索