#!/usr/bin/env perl # Copyright (c) 2000, 2003, 2006 MySQL AB, 2009 Sun Microsystems, Inc. # Use is subject to license terms. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; version 2 # of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1335 USA # # start initialition #
$VER = "1.0";
use Getopt::Long;
use Cwd;
use DBI;
$max_row_length=500000; # Don't create bigger SQL rows that this
$opt_lock=1; # lock tables
$pwd = cwd(); $pwd = "."if ($pwd eq '');
require "$pwd/server-cfg" || die "Can't read Configuration file: $!\n";
Copies tables between two database servers. If the destination table doesn\'t
exist it\'s automatically created. If the destination table exists, it
should be compatible with the source table.
Because DBI doesn\'t provide full information about the columns in a table,
some columns may not have optimal types in a create tables. Any created
tables will also not have any keys!
Usage: $0 [options] tables...
Options:
--help Show this help and exit
--from-server Source server (Default: $opt_from_server)
--from-host Source hostname (Default: $opt_from_host)
--from-db Source database name (Default: $opt_from_db)
--from-user Source user (Default: $opt_from_password)
--from-password Source password (Default: $opt_from_password)
--to-server Destination server (Default: $opt_to_server)
--to-host Destination hostname (Default: $opt_to_host)
--to-db Destination database name (Default: $opt_to_db)
--to-user Destination user (Default: $opt_to_user)
--to-password Destination password (Default: $opt_to_password)
--verbose Be more verbose
If you the server names ends with _ODBC, then this program will connect
through ODBC instead of using a native driver.
EOF
exit(0);
}
$opt_user=$opt_from_user; $opt_password=$opt_from_password;
print "- connecting to SQL servers\n"if ($opt_verbose);
$from_dbh=$from_server->connect() || die "Can't connect to source server $opt_from_server on host $opt_from_host using db $opt_from_db";
$opt_user=$opt_to_user; $opt_password=$opt_to_password;
$to_dbh=$to_server->connect() || die "Can't connect to source server $opt_to_server on host $opt_to_host using db $opt_to_db";
#### #### Copy data ####
foreach $table (@ARGV)
{
print "- querying $table\n"if ($opt_verbose);
$sth=$from_dbh->prepare("select * from $table") || die "Can't prepare query to get $table; $DBI::errstr";
$sth->execute || die "Can't execute query to get data from $table; $DBI::errstr";
# # Check if table exists; Return 1 if table exists #
sub table_exists
{
my ($server,$dbh,$table)=@_; if ($server->{'limits'}->{'group_functions'})
{
return !safe_query($dbh,"select count(*) from $table");
} if ($server->{'limits'}->{'limit'})
{
return !safe_query($dbh,"select * from $table limit 1");
}
die "Don't know how to check if table '$table' exists in destination server\n";
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.