2009-06-01 3 views

Antwort

1

Ich glaube, dass Sie ein Skript in der Sprache schreiben müssen, die Ihnen am besten gefällt. Sie können eine Liste der Tabellen in dem Schema von der Informationsschema-DB abrufen, dann über sie iterieren und alles abschneiden, was Ihnen gerade gefällt.

würde Abfrage so etwas wie:

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

bearbeiten: Hier ist ein Beispiel 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

Interessant. Wie genau iteriere ich über sie? – Monster

0

Eine andere Methode könnte sein, dass Sie diese vier Tabellen in einem neuen Schema kopieren und dann Löschen Sie das ursprüngliche Datenbankschema.

0

* nichts Einzeiler:

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