MySQL:复制/同步数据库/表的简单脚本

使用mysql复制(同步)

# mysqladmin create DB_name -u DB_user --password=DB_pass && \
mysqldump -u DB_user --password=DB_pass DB_name | mysql -u DB_user --password=DB_pass -h DB_host DB_name

使用MySQL压缩

# same as above, mysql has the "-C" flag

使用SSH加密和压缩

mysqldump [options] sourcedatabase tablename \
  | ssh -C user@remoteserver 'mysql [options]'

使用中间SQL文件和rsync,增量传送

mysqldump [options] sourcedb tbl > dump.sql
rsync [-z] dump.sql user@remoteserver:/path/to/remote/dump.sql
ssh user@remoteserver "mysql [options] < /path/to/remote/dump.sql"

使用PERL脚本

#!/usr/bin/perl
# This'll sync a table to a remote MySQL server.
# local_pass is your local password
# database_name is your database name
# remote_pass is the production server password
# database_name is the database name (shockingly enough).
# remote.mysql.server is the remote server
my $table=shift;
chomp($table);
if($table){
`mysqldump -al --password=local_pass --add-drop-table database_name $table \
 | mysql -h remote.mysql.server --password=remote_pass database_name`;


by iefreer


你可能感兴趣的:(mysql,shell,script,DUPLICATE)