MySQL转储备份文件包含以下行...
# head -40 backup20-Apr-2010-07-32.sql | grep 'CHANGE MASTER TO '
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000068', MASTER_LOG_POS=176357756;
a)我需要使用Master host,user和password等参数完成语句。
b)我还需要删除评论“ - ”
该行应该看起来像这样...
CHANGE MASTER TO MASTER_HOST='111.222.333.444', MASTER_USER='slave_user', MASTER_PASSWORD='slave_user', MASTER_LOG_FILE='mysql-bin.000068', MASTER_LOG_POS=176357756;
答案 0 :(得分:0)
head -40 backup20-Apr-2010-07-32.sql |
grep 'CHANGE MASTER TO ' |
perl -lpe "s/-- CHANGE MASTER TO/CHANGE MASTER TO MASTER_HOST='111.222.333.444', MASTER_USER='slave_user', MASTER_PASSWORD='slave_user',/"
答案 1 :(得分:0)
head -40 ORS20-Apr-2010-07-32.sql | grep 'CHANGE MASTER TO ' | sed 's/CHANGE MASTER TO/CHANGE MASTER TO MASTER_HOST='111.222.333.444', MASTER_USER='slave_user', MASTER_PASSWORD='slave_user'/g' | sed 's/^--//g'
这是正确的方法吗?
答案 2 :(得分:0)
#!/bin/bash
s="MASTER_HOST='111.222.333.444', MASTER_USER='slave_user',"
awk -vs="$s" ' /-- CHANGE MASTER TO/{
gsub("-- CHANGE MASTER TO","CHANGE MASTER TO "s)
}1 ' file >temp
mv temp file