pt-table-checksum和pt-table-sync
环境:系统bsd,标准安装,ports安装的mysql。
主172.16.21.126
从172.16.21.128
vi /etc/rc.conf
添加 mysql_enable="YES"
cp /usr/local/share/mysql/my-large.cnf /etc/my.cnf
vi /etc/my.cnf
log-bin= mysql-bin #打开logbin选项以能写到slave的 I/O线程;
server-id=1 #表示是本机的序号为1,一般来讲就是master的意思.
binlog-do-db= lixl #表示同步lixl数据库;
grant replication slave on *.* to 'repl'@'172.16.21.128' identified by '123456';
flush privileges;
重启主库mysql:/usr/local/etc/rc.d/mysql-server restart
*********************************************************************************
vi /etc/rc.conf
添加 mysql_enable="YES"
cp /usr/local/share/mysql/my-large.cnf /etc/my.cnf
vi /etc/my.cnf
server-id=2 #表示是本机的序号为2.
replicate-do-db= lixl #表示被同步的lixl数据库;
重启从mysql
*********************************************************************************
主库上:show master status
从库上:
stop slave;
mysql>change master to master_host =
'172.16.21.126',master_user='repl',master_password='123456',,master_log_file='mysql-bin.000006',master_log_pos=98; //98
这不能加引号,要不然报错。
start slave;
show slave status\G
*********************************************************************************
被证实的问题,即便我数据库里面没有lixl,搭建的过程,slave本应该是yes的地方也不会报错。
repl这个账号只存在master主机上
*********************************************************************************
主库上操作:
在主库上创建lixl数据库
在lixl库下面创建xf表
create table xf (id int);
insert into xf values(1),(11),(2),(22),(3),(33),(4),(44),(5),(55);
**********************************************************************************
问题:如果我在主库上删除数据,从库上会不会也会减少? 答案:会的。 export
**********************************************************************************
从库上的操作:
delete from lixl.xf where id in (1,2,3,4,5);
**********************************************************************************
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
到目前为止:主从数据之间数据有差异了。
———————————————————————————————————————————
下面在主库上安装percona-tookit,我是在网上下载好的软件,然后传到master上去的。
1.解压 tar xf percona-toolkit-2.1.1.tar.gz
2.cd percona-toolkit-2.1.1
3.perl Makefile.PL 提示perl:command not found
4.cd /usr/ports/lang/perl5.12
5.make install clean
6.cd /usr/ports/databases/p5-DBD-mysql50 &&make install clean //不然报Warning: prerequisite DBD::mysql 3 not found.
7.perl Makefile.PL&&make&&make install
***********************************************************************************************************************
用pt-table-checksum 比较两台服务器之间数据的差异
**************************************************
ma# /usr/local/bin/pt-table-checksum --nocheck-replication-filters --replicate=lixl.checksums --databases=lixl --tables=xf
h=127.0.0.1,u=root,P=3306
Failed to SET SESSION innodb_lock_wait_timeout=1: DBD::mysql::db do failed: Unknown system variable
'innodb_lock_wait_timeout' [for Statement "SET SESSION innodb_lock_wait_timeout=1"] at /usr/local/bin/pt-table-checksum
line 6009.
The current innodb_lock_wait_timeout value 50 is greater than the --lock-wait-timeout value 1 and the variable cannot be
changed. innodb_lock_wait_timeout is only dynamic when using the InnoDB plugin. To prevent this warning, either specify
--lock-wait-time=50, or manually set innodb_lock_wait_timeout to a value less than or equal to 1 and restart MySQL.
Cannot connect to P=3306,h=172.16.21.128,u=root
TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE
10-24T10:00:48 0 0 10 1 0 0.588 lixl.xf
####****###处理:vi /etc/my.cnf
修改 innodb_lock_wait_timeout =1
**************************************************************************
重启主库mysql服务;更改mysql从库stop slave,change,start slave;重新启动mysql服务器,
没有解决问题,这步
********************************************************************************************
去从库赋权限:mysql> grant all on *.* to root@172.16.21.126;
主库上:ma# /usr/local/bin/pt-table-checksum --nocheck-replication-filters --replicate=lixl.checksums --databases=lixl --
tables=xf h=127.0.0.1,u=root,P=3306
TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE
10-24T16:30:14 0 1 18 1 0 0.010 lixl.xf
ma# /usr/local/bin/pt-table-sync h=127.0.0.1, --databases lixl,t=xf h=172.16.21.128 --no-check-slave --exec
*************************************************************************************************
参见:http://www.cnblogs.com/zhoujinyi/archive/2013/05/09/3067045.html
http://www.percona.com/forums/questions-discussions/percona-toolkit/9577-pt-table-sync-script
飞鸿无痕的cu博客