2009-06-01 88 views

回答

1

我相信你必须用最喜欢的语言写一个脚本。您可以从information_schema db中获取模式中的表的列表,然后对它们进行迭代,截断任何您感觉的内容。

查询会是这样的:

SELECT table_name FROM information_schema.tables WHERE table_schema = 'test' AND table_name NOT IN ('table1', 'table2'); 

编辑:下面是一个使用Perl的一个例子:

use strict; 
use warnings; 
use DBI; 

my $dbh = DBI->connect("some_dsn"); 

my $sth = $dbh->prepare(q{SELECT table_name FROM information_schema.tables WHERE table_schema = 'test' AND table_name NOT IN ('table1', 'table2')}); 
$sth->execute(); 
$sth->bind_columns(\my $table_name); 

while($sth->fetch) { $dbh->do(q{TRUNCATE TABLE } . $table_name) } 
+0

有趣。但是,我究竟如何迭代它们呢? – Monster 2009-06-01 15:41:25

0

另一种方法可能是你复制这四个表中的一个新的架构,然后删除原始数据库模式。

0

* nix中的一行:

for i in `mysql -e "show tables MY_DB" | grep -vE "(table1|table2)"`; do mysql -e"TRUNCATE ${i}" MY_DB; done 
相关问题