主从配置背景

主机192.168.1.213

从机192.168.1.214

这两台之前是做过同步,但不知什么时候停止了同步,所以现在要重新进行同步工作

主机环境情况

213机子为主机,并且在213的机子上已开放多个mysqld服务的端口

一个项目对应一个端口,一个端口对应一个实例

现在要配置已3303的端口实例为主的主机,214也是3303端口的从机

在主从机的my.cnf文件上都开启日志

log-bin=/data/mysql_data_3303/bin


开启完后,在主机授权从机

grant replication slave on *.* to 'slave'@'192.168.1.214' identified by '123214'

查看主机的当前状况

SHOW master\G


从机重新获取主机的当前状态信息

change master to master_host='192.168.1.213',master_user='root',master_password='123',master_log_file='bin.002031',MASTER_LOG_POS=107035;



查看从机的状态

SHOW SLAVE\G


发现有错误信息

Last_SQL_Error: Error 'Duplicate entry '2' for key 'PRIMARY'' on query. Default database: 'xy_db_items'. Query: 'insert into `xy_tbl_money`(`AuthID`,`RoleID`,`YinLiang`,`YuanBao`,`LiQuan`,`BangPaiJiFen`,`BangGong`,`LiLian`,`LanXianMoDou`,`ZiXianMoDou`,`XiuLianZhi`,`ZhenYingJiFen`,`JingJiJiFen`,`XianHun`,`YaoHun`,`ChongZhiJifen`,`Extra1`,`Extra2`,`Extra3`,`Extra4`,`Extra5`,`Extra6`,`Extra7`,`LastUpdateTime`)


查看从库的错误日志信息

tail -n 800 -f /data/data_mysql3303/error.err

130603 11:23:54 [ERROR] Slave SQL: Could not execute Update_rows event on table xy_db_gm.xy_tbl_roleinfosums; Can't find record in 'xy_tbl_roleinfosums', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log bin.002031, end_log_pos 139612, Error_code: 1032

130603 11:23:54 [Warning] Slave: Can't find record in 'xy_tbl_roleinfosums' Error_code: 1032

130603 11:23:54 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'bin.002031' position 139395


在主库中查询bin.002031这个文件的信息记录

进主库进行查询

[root@linux-i77abin]#./mysqlbinlog --no-defaults --base64-output=decode-rows -v -v /data/mysql_data_3303/bin.002031 | grep -A 20 '288785' |more


#130603  9:56:57 server id 3303  end_log_pos 139395 Xid = 5316

COMMIT/*!*/;

# at 139395

#130603  9:56:57 server id 3303  end_log_pos 139467 Querythread_id=20exec_time=0error_code=0

SET TIMESTAMP=1370224617/*!*/;

BEGIN

/*!*/;

# at 139467

# at 139532

#130603  9:56:57 server id 3303  end_log_pos 139532 Table_map: `xy_db_gm`.`xy_tbl_roleinfosums` mapped to number 36

#130603  9:56:57 server id 3303  end_log_pos 139612 Update_rows: table id 36 flags: STMT_END_F

### UPDATE xy_db_gm.xy_tbl_roleinfosums

### WHERE

###   @1=1471 /* LONGINT meta=0 nullable=0 is_null=0 */

###   @2=281474976710660 /* LONGINT meta=0 nullable=0 is_null=0 */

###   @3=43 /* INT meta=0 nullable=0 is_null=0 */

###   @4=0 /* INT meta=0 nullable=0 is_null=0 */

### SET

###   @1=1471 /* LONGINT meta=0 nullable=0 is_null=0 */

###   @2=281474976710660 /* LONGINT meta=0 nullable=0 is_null=0 */

###   @3=44 /* INT meta=0 nullable=0 is_null=0 */

###   @4=0 /* INT meta=0 nullable=0 is_null=0 */

# at 139612


在从库中插入这个信息

INSERT INTO xy_tbl_roleinfosums VALUES(1471,281474976710660,43,0);


进行重启从库的同步信息 slave restart\G


有报错,继续排错信息。


在进行排错的过程中出现了只同步几个库,而不进行同步全部库的需要

则进行修改主库的my.cnf文件

#需要同步的库
replicate-do-db=test1
#设置不同步的数据库
replicate-ignore-db=TEST2


对主库3303端口进行重启

服务停止

/usr/local/mysql516-3303/bin/mysqladmin -uroot -p123 -S /tmp/mysql3303.sock shutdown

服务启动

/bin/sh /usr/local/mysql516-3303/bin/mysqld_safe --defaults-file=/usr/local/mysql516-3303/my.cnf --datadir=/data/mysql_data_3303/


但是重启后发现/tmp/mysql3303.sock的文件丢失

进行查询问题所在


查询后忽然发现可能是启动不正常造成的

mysql.sock的丢失主要是因为更改了机器名,在没有正确关闭mysqld的情况下,去执行mysqld_safe,这样他就删除已经运行的mysql.sock了。


现在只能能明天重启服务器后看会不会重新正常存在。

主从重新建立连接今天只能先暂告一段落。