MariaDB 复制设置后出现重复键错误
Duplicate key error after MariaDB replication setup
寻找有关我在尝试在单个主服务器和复制服务器之间执行基本复制设置时继续做错什么的指导。
通过多年来的多次试验,这充其量是不一致的。我最近的尝试(步骤)如下所示,这是几个网站的结晶,包括 MariaDB 支持网站。
目标:使用mariabackup或其他推荐的方法从主服务器备份数据库,恢复到复制服务器并成功将数据从主服务器复制到复制服务器。
使用 Mariabackup 捕获数据备份
在主服务器上
运行 在 MySQL 命令提示符下执行以下命令
flush privileges; flush tables with read lock;
当数据库被锁定时
运行这条命令要备份
mariabackup --defaults-file="m:\mariadb\my.ini" --backup --target-dir="m:\backup" --user user --password pass
备份后,运行准备命令
mariabackup --defaults-file="m:\mariadb\my.ini" --prepare --target-dir="m:\backup" --user user --password pass
注意
准备完成后,确保在 MariaDB 命令提示符 window.
中 运行 'unlock tables'
prepare 命令将显示 binlog 文件和在 CHANGE MASTER TO 中使用的位置,因此请务必在完成后捕获 prepare 命令的输出。
准备命令的示例输出
mariabackup based on MariaDB server 10.3.12-MariaDB Win64 (AMD64)
mariabackup: cd to m:\backup\
mariabackup: This target seems to be not prepared yet.
mariabackup: using the following InnoDB configuration for recovery:
mariabackup: innodb_data_home_dir = .
mariabackup: innodb_data_file_path = ibdata1:10M:autoextend
mariabackup: innodb_log_group_home_dir = .
mariabackup: Starting InnoDB instance for recovery.
mariabackup: Using 104857600 bytes for buffer pool (set by --use-memory paramete
r)
2020-11-02 22:46:49 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocke
d functions
2020-11-02 22:46:49 0 [Note] InnoDB: Uses event mutexes
2020-11-02 22:46:49 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-11-02 22:46:49 0 [Note] InnoDB: Number of pools: 1
2020-11-02 22:46:49 0 [Note] InnoDB: Using SSE2 crc32 instructions
2020-11-02 22:46:49 0 [Note] InnoDB: Initializing buffer pool, total size = 100M
, instances = 1, chunk size = 100M
2020-11-02 22:46:49 0 [Note] InnoDB: Completed initialization of buffer pool
2020-11-02 22:46:49 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN
=936805148847
2020-11-02 22:46:49 0 [Note] InnoDB: Last binlog file '.\master-bin.000003', pos
ition 167707395
Last binlog file .\master-bin.000003, position 167707395
201102 22:46:50 completed OK!
正在恢复数据库
将备份目录从主服务器复制到从服务器上 DB 驱动器的根目录
登录从服务器,打开命令提示符到备份目录
运行复制恢复备份到slave数据目录的命令
mariabackup --copy-back --target-dir="M:\backup" --datadir="m:\mariadb\data" --user infinity --password infinitydb
在从服务器上启动MariaDB服务
运行 以下将 master 更改为具有适当值的 command
例子
CHANGE MASTER TO master_host="idk3-vm5", master_log_file='master-bin.000003', master_log_pos=167707395, master_port=3306, master_user="repl", master_password="repl", master_use_gtid=current_pos;
启动并检查slave
start slave;
show slave status \G
开始复制时出错
MariaDB [(none)]> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Queueing master event to the relay log
Master_Host: idk3-vm5
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000002
Read_Master_Log_Pos: 604529766
Relay_Log_File: idk3-vm8-relay-bin.000002
Relay_Log_Pos: 1631
Relay_Master_Log_File: master-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table:
Last_Errno: 1062
Last_Error: Error 'Duplicate entry 'idk3-vm8-OrderInjector' for key 'PRIMARY'' on query. Default database: 'idf'. Query: 'INSERT INTO `idf`. `idf_client_version` (`idf`.`idf_client_version`.`HOSTNAME`,`idf`.`idf_client_ve rsion`.`SOFTWARE`,`idf`.`idf_client_version`.`VERSION`,`idf`.`idf_client_version `.`LAST_CONNECTED`) VALUES ('idk3-vm8','OrderInjector','20.2.11','2020-11-02 11: 29:13')'
Skip_Counter: 0
Exec_Master_Log_Pos: 1331
Relay_Log_Space: 604530378
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1062
Last_SQL_Error: Error 'Duplicate entry 'idk3-vm8-OrderInjector' for key 'PRIMARY'' on query. Default database: 'idf'. Query: 'INSERT INTO `idf`. `idf_client_version` (`idf`.`idf_client_version`.`HOSTNAME`,`idf`.`idf_client_ve rsion`.`SOFTWARE`,`idf`.`idf_client_version`.`VERSION`,`idf`.`idf_client_version `.`LAST_CONNECTED`) VALUES ('idk3-vm8','OrderInjector','20.2.11','2020-11-02 11: 29:13')' Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: Slave_Pos
Gtid_IO_Pos: 0-1-701693
Replicate_Do_Domain_Ids: Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Slave_DDL_Groups: 0 Slave_Non_Transactional_Groups: 0
Slave_Transactional_Groups: 3 1 row in set (0.003 sec)
鉴于我已刷新权限、刷新表并锁定数据库然后捕获备份,我不明白为什么在恢复并完成复制配置后我继续获取重复密钥。
如果有人能帮助我理解我做错了什么,我将不胜感激。
在从站状态下,二进制日志正在从文件 master-bin.000002
中读取,同时备份已完成,直到 master_log_file='master-bin.000003', master_log_pos=167707395.
请在从站上执行 运行 命令服务器
reset slave all;
CHANGE MASTER TO master_host="idk3-vm5",
master_log_file='master-bin.000003', master_log_pos=167707395,
master_port=3306, master_user="repl", master_password="repl";
start slave;
注意:此处不需要 master_use_gtid=current_pos;
。一旦 slave 不同步,您就可以使用 GTID 进行更改。
寻找有关我在尝试在单个主服务器和复制服务器之间执行基本复制设置时继续做错什么的指导。
通过多年来的多次试验,这充其量是不一致的。我最近的尝试(步骤)如下所示,这是几个网站的结晶,包括 MariaDB 支持网站。
目标:使用mariabackup或其他推荐的方法从主服务器备份数据库,恢复到复制服务器并成功将数据从主服务器复制到复制服务器。
使用 Mariabackup 捕获数据备份
在主服务器上
运行 在 MySQL 命令提示符下执行以下命令
flush privileges; flush tables with read lock;
当数据库被锁定时
运行这条命令要备份
mariabackup --defaults-file="m:\mariadb\my.ini" --backup --target-dir="m:\backup" --user user --password pass
备份后,运行准备命令
mariabackup --defaults-file="m:\mariadb\my.ini" --prepare --target-dir="m:\backup" --user user --password pass
注意 准备完成后,确保在 MariaDB 命令提示符 window.
中 运行 'unlock tables'prepare 命令将显示 binlog 文件和在 CHANGE MASTER TO 中使用的位置,因此请务必在完成后捕获 prepare 命令的输出。
准备命令的示例输出
mariabackup based on MariaDB server 10.3.12-MariaDB Win64 (AMD64)
mariabackup: cd to m:\backup\
mariabackup: This target seems to be not prepared yet.
mariabackup: using the following InnoDB configuration for recovery:
mariabackup: innodb_data_home_dir = .
mariabackup: innodb_data_file_path = ibdata1:10M:autoextend
mariabackup: innodb_log_group_home_dir = .
mariabackup: Starting InnoDB instance for recovery.
mariabackup: Using 104857600 bytes for buffer pool (set by --use-memory paramete
r)
2020-11-02 22:46:49 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocke
d functions
2020-11-02 22:46:49 0 [Note] InnoDB: Uses event mutexes
2020-11-02 22:46:49 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-11-02 22:46:49 0 [Note] InnoDB: Number of pools: 1
2020-11-02 22:46:49 0 [Note] InnoDB: Using SSE2 crc32 instructions
2020-11-02 22:46:49 0 [Note] InnoDB: Initializing buffer pool, total size = 100M
, instances = 1, chunk size = 100M
2020-11-02 22:46:49 0 [Note] InnoDB: Completed initialization of buffer pool
2020-11-02 22:46:49 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN
=936805148847
2020-11-02 22:46:49 0 [Note] InnoDB: Last binlog file '.\master-bin.000003', pos
ition 167707395
Last binlog file .\master-bin.000003, position 167707395
201102 22:46:50 completed OK!
正在恢复数据库 将备份目录从主服务器复制到从服务器上 DB 驱动器的根目录
登录从服务器,打开命令提示符到备份目录
运行复制恢复备份到slave数据目录的命令
mariabackup --copy-back --target-dir="M:\backup" --datadir="m:\mariadb\data" --user infinity --password infinitydb
在从服务器上启动MariaDB服务
运行 以下将 master 更改为具有适当值的 command
例子
CHANGE MASTER TO master_host="idk3-vm5", master_log_file='master-bin.000003', master_log_pos=167707395, master_port=3306, master_user="repl", master_password="repl", master_use_gtid=current_pos;
启动并检查slave
start slave;
show slave status \G
开始复制时出错
MariaDB [(none)]> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Queueing master event to the relay log
Master_Host: idk3-vm5
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000002
Read_Master_Log_Pos: 604529766
Relay_Log_File: idk3-vm8-relay-bin.000002
Relay_Log_Pos: 1631
Relay_Master_Log_File: master-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table:
Last_Errno: 1062
Last_Error: Error 'Duplicate entry 'idk3-vm8-OrderInjector' for key 'PRIMARY'' on query. Default database: 'idf'. Query: 'INSERT INTO `idf`. `idf_client_version` (`idf`.`idf_client_version`.`HOSTNAME`,`idf`.`idf_client_ve rsion`.`SOFTWARE`,`idf`.`idf_client_version`.`VERSION`,`idf`.`idf_client_version `.`LAST_CONNECTED`) VALUES ('idk3-vm8','OrderInjector','20.2.11','2020-11-02 11: 29:13')'
Skip_Counter: 0
Exec_Master_Log_Pos: 1331
Relay_Log_Space: 604530378
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1062
Last_SQL_Error: Error 'Duplicate entry 'idk3-vm8-OrderInjector' for key 'PRIMARY'' on query. Default database: 'idf'. Query: 'INSERT INTO `idf`. `idf_client_version` (`idf`.`idf_client_version`.`HOSTNAME`,`idf`.`idf_client_ve rsion`.`SOFTWARE`,`idf`.`idf_client_version`.`VERSION`,`idf`.`idf_client_version `.`LAST_CONNECTED`) VALUES ('idk3-vm8','OrderInjector','20.2.11','2020-11-02 11: 29:13')' Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: Slave_Pos
Gtid_IO_Pos: 0-1-701693
Replicate_Do_Domain_Ids: Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Slave_DDL_Groups: 0 Slave_Non_Transactional_Groups: 0
Slave_Transactional_Groups: 3 1 row in set (0.003 sec)
鉴于我已刷新权限、刷新表并锁定数据库然后捕获备份,我不明白为什么在恢复并完成复制配置后我继续获取重复密钥。
如果有人能帮助我理解我做错了什么,我将不胜感激。
在从站状态下,二进制日志正在从文件 master-bin.000002
中读取,同时备份已完成,直到 master_log_file='master-bin.000003', master_log_pos=167707395.
请在从站上执行 运行 命令服务器
reset slave all;
CHANGE MASTER TO master_host="idk3-vm5", master_log_file='master-bin.000003', master_log_pos=167707395, master_port=3306, master_user="repl", master_password="repl";
start slave;
注意:此处不需要 master_use_gtid=current_pos;
。一旦 slave 不同步,您就可以使用 GTID 进行更改。