Heim > Datenbank > MySQL-Tutorial > Hauptteil

Mysql主从不同步问题处理

WBOY
Freigeben: 2016-06-07 16:25:54
Original
1244 Leute haben es durchsucht

由于各种原因,mysql主从架构经常会出现数据不一致的情况出现,大致归结为如下几类1:备库写数据2:执行non-deterministicquery3:回滚掺杂事务表和非事务表的事务4

 

一:安装percona-toolkit

# yum -y  install perl-Time-HiRes # wget  # tar -zxvpf percona-toolkit-2.2.13.tar.gz  # cd percona-toolkit-2.2.13 # perl Makefile.PL  # make  # make install



1. 先校验

#  pt-table-checksum --user=root --password=123456 \   --host=192.168.1.205 --port=3306 \   --databases=test  --tables=t2  --recursion-method=processlist \   --no-check-binlog-format  --nocheck-replication-filters \   --replicate=test.checksums# pt-table-sync  --execute  --replicate \ test.checksums  --sync-to-master h=192.168.1.207,P=3306,u=root,p=123456

SELECT * FROM test.checksums WHERE master_cnt  this_cnt OR master_crc  this_crc OR ISNULL(master_crc)  ISNULL(this_crc)

 

1: 主库上建表,插入测试数据

mysql> create table t2 (id int primary key,name varchar(100) not null,salary int); mysql> CREATE PROCEDURE test_insert ()        BEGIN        DECLARE i INT DEFAULT 0;        WHILE i CALL test_insert();

从库上校验当前数据的同步情况为正常。

wKioL1T0I63D5z_sAAQ-M6dFnmo722.jpg

从库上删除一半的数据

mysql> delete from t2 where id > 5000; Query OK, 4999 rows affected (0.14 sec)   mysql> select count(*) from t2; +----------+ | count(*) | +----------+ |     5001 | +----------+ 1 row in set (0.01 sec)

进行校验:

#  pt-table-checksum --user=root --password=123456 \   --host=192.168.1.205 --port=3306 \   --databases=test  --tables=t2  --recursion-method=processlist \   --no-check-binlog-format  --nocheck-replication-filters \   --replicate=test.checksums

wKiom1T0It-xh_2wAALWSm1-Ihs867.jpg

mysql> SELECT * FROM test.checksums WHERE master_cnt  this_cnt OR master_crc  this_crc OR ISNULL(master_crc)  ISNULL(this_crc)

wKioL1T0JBLTIkLXAAPYSaaLP2c662.jpg

# pt-table-sync  --execute  --replicate \  test.checksums  --sync-to-master h=192.168.1.207,P=3306,u=root,p=123456

wKioL1T0JECw6iLQAAMwzE_kngo764.jpg

wKioL1T0JICjbqboAAXA0u2VFSY703.jpg

主从库my.cnf文件添加如下配置项后重启数据库实例

character_set_client=utf8 character_set_server=utf8

wKiom1T0I6TAuiq3AAN-S7fbvMQ746.jpg

wKioL1T0JMCCjs7QAAUKSFnkXKg698.jpg

 # pt-table-sync  --execute  --replicate \  test.checksums   --charset=utf8 \  --sync-to-master h=192.168.1.207,P=3306,u=root,p=123456

wKiom1T0I9zAwLW7AAQS_GWreLI996.jpg

本文出自 “斩月” 博客,谢绝转载!

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!