mysql - 将表从服务器A复制到服务器B

标签 mysql bash shell

我们有一个运行良好的脚本,我们用它来将一个巨大的数据库从服务器 A 复制到服务器 B。现在我只想将一个表从服务器 A 复制到服务器 B,并将表名作为变量,因此脚本应该只询问表名并将表从 A 复制到 B。 这是我制作的脚本,我必须承认我在 shell 脚本方面不是很有经验。

#!/bin/sh

#Run on Server A
TABLENAME=$1

echo $TABLENAME

_now=$(date +"%A %d-%m-%Y "at" %T")

#Copy table $TABLENAME  from server A to server B
#Dump table into /directory server A
mysqldump -u admin -p'*****' database_name $TABLENAME >             /directory/$TABLENAME.sql
# Copie table to server B
scp /directory/$TABLENAME.sql root@server_b.domain.com:/directory/
# Replace table in database on server B
ssh root@server_b.domain.com "mysql -f -u admin -p'******' database_name -e     'source /directory/$TABLENAME.sql'"  
#Remove file on server B
ssh root@server_b.domain.com "rm /directory/$TABLENAME.sql"
#Remove file on A
rm /directory/$TABLENAME.sql

这是我得到的错误:

.sql                                                                                                                                                                                                                                  
./script_file_name: line 19: unexpected EOF while looking for matching `"'
./script_file_name: line 22: syntax error: unexpected end of file

谢谢

最佳答案

作为命令的一部分,您缺少引号 (",')。

ssh root@server_b.domain.com "mysql -f -u admin -p'******' database_name -e     'source /directory/$TABLENAME'"

关于mysql - 将表从服务器A复制到服务器B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42994924/

相关文章:

mySQL 从单个表中为每个 user_id 选择时间戳接近的行

linux - 根据输入文件从 csv 中删除行

bash - 在临时文件夹中运行脚本

unix shell 脚本以获取格林威治标准时间 30 分钟前的日期

php - 如何在 JavaScript 中显示 MySQL 中 "onclick"的下一个结果?

mysql - 根据 information_schema 中的 column_type 更改选择值

mysql - 几年前创建了这个 vBulletin 论坛,现在它向我发送垃圾邮件错误

bash - 是否可以获取函数体中的函数名?

linux - 使用用户输入运行 crontab

node.js - AWK 命令在 Nodejs 内失败