Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql data is out of sync

Shulou Source: shulou.com Published: 2022-06-01 17:07:24 10月27日 Update

The mysql database is suddenly out of sync.

View the status of slave

Show slave status\ G

View the log

2019-03-11 18:40:03 10283 [ERROR] Slave SQL: Error 'Duplicate entry' 39 'for key' PRIMARY'' on query. Default database: 'db_jd'. Query: 'insert into tb_goods values (null,'ty','10.45','27','')', Error_code: 1062

2019-03-11 18:40:03 10283 [Warning] Slave: Duplicate entry '39' for key' PRIMARY' Error_code: 1062

2019-03-11 18:40:03 10283 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000003' position 10743.

It is said on the Internet that it is possible to write in slave.

The solution is

Mysql > stop slave

Mysql > set GLOBAL SQL_SLAVE_SKIP_COUNTER=1

Mysql > start slave

It still doesn't work. By the way, my database is a dual-master model. Of course, slave can be written.

I also saw on the Internet that the format of binlog was incorrect, and then checked my.cnf.

It was found that a few items were indeed missing, and the contents in the red box were not originally found, but were added later.

Then restart mysql

View the log

Another error was reported.

2019-03-11 19:34:36 454 [ERROR] Slave SQL: Slave failed to initialize relay log info structure from the repository, Err or_code: 1872

It was said on the Internet that it was caused by the previous residual files, so the two files were deleted.

Rm-rf slave-relay-bin.index

Rm-rf relay-log.info

Restart mysql

Then reconfigure mysql synchronization to enter mysql1

Mysql > stop slave

Query OK, 0 rows affected (0.05 sec)

View mysql-bin and position on mysql2

Mysql > show master status

Mysql > change master to master_host='192.168.255.57',master_port=3306,master_user='zhangsan',master_password='123456',m aster_log_file='mysql-bin.000006',master_log_pos=120

Query OK, 0 rows affected, 2 warnings (0.41 sec)

Mysql > start slave

Query OK, 0 rows affected (0.05 sec)

Mysql > show slave status\ G

Mysql2 is also reconfigured

Mysql > stop slave

Query OK, 0 rows affected (0.05 sec)

View mysql-bin and position on mysql1

Mysql > show master status

Mysql > change master to master_host='192.168.255.52',master_port=3306,master_user='zhangsan',master_password='123456',m aster_log_file='mysql-bin.000008',master_log_pos=120

Query OK, 0 rows affected, 2 warnings (0.30 sec)

Mysql > start slave

Query OK, 0 rows affected (0.03 sec)

Mysql > show slave status\ G

Then insert the data into the database and synchronize.

Tags: Data synchronization database file log say configuration no no right two content method by format model state or check residue Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei NVidia MariaDB Apple Xiaomi