【发布时间】:2021-02-08 14:27:04
【问题描述】:
导入 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.
脚本
#!/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
【问题讨论】: