MySQL双主(Master-Master)同步
来源:互联网 发布:斗鱼主播唱歌软件 编辑:程序博客网 时间:2024/05/20 19:15
MySQL双主同步步骤(Linux服务器):
1.分别找到两个MySQL下的my.cnf配置文件,分别加入:
[mysqld]server-id = 1log-bin=/data0/mysql/3306/binlog/binlogbinlog-do-db = Master_1binlog-ignore-db=mysqlbinlog-ignore-db=obtbinlog-ignore-db=performance_schemabinlog-ignore-db=testbinlog-ignore-db=information_schemalog-slave-updatessync_binlog=1auto_increment_offset=1auto_increment_increment=2replicate-do-db = Master_1replicate-ignore-db = mysqlreplicate-ignore-db = obtreplicate-ignore-db = performance_schemareplicate-ignore-db = testreplicate-ignore-db = information_schema
[mysqld]server-id = 2log-bin=/data/mysql/binlog/binlogbinlog-do-db = Master_2binlog-ignore-db=mysqlbinlog-ignore-db=testbinlog-ignore-db=information_schemalog-slave-updatessync_binlog=1auto_increment_offset=2auto_increment_increment=2replicate-do-db = Master_2replicate-ignore-db = mysqlreplicate-ignore-db = testreplicate-ignore-db = information_schema
server-id,auto_increment_offset为区别处
2.分别重启两台MySQL
service mysqld restart
注意:若此时发现启动失败,查看err日志文件显示:File '/data/mysql/binlog/binlog.index' not found
进入binlog目录 进行授权操作 再次启动mysql服务即可
[root@trade-api mysql]# chown -R mysql:mysql binlog[root@trade-api mysql]# service mysqld restart
mysql>grant replication slave,file on *.* to 'root'@'对方IP' identified by '密码';mysql>flush privileges; mysql>grant replication slave,file on *.* to 'root'@'对方IP' identified by '密码';mysql>flush privileges;
4.锁定表
mysql>flush tables with read lock;
5.查看各自状态
mysql> show master status;+---------------+----------+--------------+-------------------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+---------------+----------+--------------+-------------------------------+| binlog.000002 | 4890 | Master_1 | mysql,test,information_schema |+---------------+----------+--------------+-------------------------------+
mysql> show master status;+---------------+----------+--------------+------------------------------------------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+---------------+----------+--------------+------------------------------------------------------+| binlog.000028 | 7078 | Master_1 | mysql,obt,performance_schema,test,information_schema |+---------------+----------+--------------+------------------------------------------------------+
6.建立平行库
[root@test7 ~]# scp -P 端口(默认22) root@IP地址:/tmp/Master_1.sql .
# mysql -uroot -p test < /tmp/Master_1.sql7.同步两端数据库
mysql> change master to master_host='对方IP',master_user='root',master_password='密码',master_log_file='binlog.000028',master_log_pos=7078;
mysql> change master to master_host='对方IP',master_user='root',master_password='密码',master_log_file='binlog.000002',master_log_pos=4890;8.解锁
mysql> UNLOCK TABLES;9.分别启动slave
mysql>START SLAVE;
注:如果slave报错(Last_SQL_Error有信息)在slave端执行:
stop slave;
set global sql_slave_skip_counter=1;跳过一次错误
start slave;
错误:
Last_Error: Could not execute Delete_rows event on table obt.t_tour_label_map; Can't find record in 't_tour_label_map', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql_log-bin.000062, end_log_pos 98278275
根据错误分析具体原因:
1.导出主库mysql_log_bin.000062
[root@db-master log-bin]# mysqlbinlog mysql_log-bin.000062 --base64-output=decode-rows -v > mysql_log-bin.000062.log
2.找到pos所在位置
vi mysql_log-bin.000062.log
?end_log_pos 98278275
3.查看具体详情
#150918 11:09:55 server id 1 end_log_pos 98278275 CRC32 0x3e1f3e3b Delete_rows: table id 1220 flags: STMT_END_F### DELETE FROM `obt`.`t_tour_label_map`### WHERE### @1=239664### @2=702### @3='402881dd4a576a1a014a576ab6810010'# at 98278275
发现该字段未出现在从库中,原因查明
0 0
- MySQL双主(Master-Master)同步
- MySQL双主(master-master)+半同步(Semisync Replication)
- mysql 同步 master-slave
- MongoDB Master+Master同步
- mySQL master slave同步修复
- MySQL Master Slave同步配置
- MySQL Master Slave同步配置
- MySQL Dual-Master 双向同步
- Mysql Master-Master Replication MYSQL数据库主主同步设置
- 重置mysql主从同步(MySQL Reset Master-Slave Replication)
- Mysql主主备份(master-master)
- mysql同步复制M-M(master master)模式
- MYSQL 的 MASTER到MASTER的主主循环同步
- MYSQL 的 MASTER到MASTER的主主循环同步
- MYSQL 的 MASTER到MASTER的主主循环同步
- MYSQL 的 MASTER到MASTER的主主循环同步
- mysql同步复制M-M(master master)模式
- MySQL Master 到 Master 的同步设置(参考链接)
- 原型模式
- 搜索引擎核心读书心得3:分布式爬虫
- 约瑟夫问题
- HDU 1867 — A + B for you again
- model
- MySQL双主(Master-Master)同步
- hdu1869六度分离【最短路dijkstra&&SPFA&&floyd】
- android 手机屏幕横屏竖屏切换
- objective-c类目Category属性的实现方法
- 重视不确定性
- java 之 语言基础
- Choose the best route HDU杭电2680【dijkstra算法 || SPFA】
- 详细整理:UITableView优化技巧
- Spring MVC 教程,快速入门,深入分析