简体   繁体   English

无法恢复从属复制

[英]Can't restore slave replication

While importing a mysqldump this error is returned while importing导入 mysqldump 时,导入时返回此错误

# sh restore_db_replication.sh
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
dynaccount_dump.sql.gz                                                                    100%  265MB  97.4MB/s   00:02
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1776 (HY000) at line 31: Parameters MASTER_LOG_FILE, MASTER_LOG_POS, RELAY_LOG_FILE and RELAY_LOG_POS cannot be set when MASTER_AUTO_POSITION is active.
96.0KiB 0:00:00 [4.93MiB/s] [>                                                                             ]  0%
mysql: [Warning] Using a password on the command line interface can be insecure.

The script剧本

#!/bin/sh

slave_pass='xxx'

master_host='server.com'
master_pass='xxx'

ssh -o StrictHostKeyChecking=no root@$master_host 'mysqldump -u root -p'"$master_pass"' --master-data --single-transaction --hex-blob --routines --triggers --events --quick --add-drop-database --extended-insert --databases name-of-db | gzip > /root/dump.sql.gz'

scp -o StrictHostKeyChecking=no root@$master_host:/root/dump.sql.gz /root

mysql -u root_slave -p$slave_pass -e "stop slave; CHANGE MASTER TO MASTER_HOST='$master_host', MASTER_USER='repl', MASTER_PASSWORD='$master_pass', MASTER_PORT=3306, MASTER_AUTO_POSITION=1; reset master;"

pv /root/dump.sql.gz | gunzip | mysql -u root_slave -p$slave_pass
mysql -u root_slave -p$slave_pass -e "start slave"

echo "\nShow slave status? [Y/n]"
read SHOW_STATUS

if [ "$SHOW_STATUS" = "y" ] || [ "$SHOW_STATUS" = "" ]; then
    mysql -u root_slave -p$slave_pass -e "show slave status\G;"
fi

The error is due to the fact that GTID replication is set to OFF该错误是由于 GTID 复制设置为 OFF

and MASTER_AUTO_POSITION=1和 MASTER_AUTO_POSITION=1

and you did not reset the slave after stopping it.并且您在停止从站后没有重置它。

The solution is one of the following:解决方案是以下之一:

(1) If you want slave to start reading from the point when this backup is created then do: (1) 如果您希望从站从创建此备份时开始读取,请执行以下操作:

In mysqldump command (line 8in the script):在 mysqldump 命令中(脚本第 8 行):

--set-gtid-purged=ON

After "stop slave;"在“停止奴隶”之后; in line 12 of the script where you have:在脚本的第 12 行中,您拥有:

mysql -u root_slave -p$slave_pass -e "stop slave; mysql -u root_slave -p$slave_pass -e "停止从机;

reset slave;

(2) If you want slave to start reading from the beginning (2)如果想让slave从头开始读取

In line 12在第 12 行

Also after stop slave add:同样在停止从站后添加:

reset slave;

And

Change:改变:

MASTER_AUTO_POSITION=1

To:至:

MASTER_AUTO_POSITION=0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM