mysql 主主+主从笔记
来源:互联网 发布:手机垃圾清理软件 编辑:程序博客网 时间:2024/06/05 02:22
环境
Ubuntu 14.04.4 LTS *3 分别是master1(192.168.42.28), master2(192.168.42.29), slave1(192.168.42.33)测试下只有master1有从
配置
vim /etc/mysql/my.cnf #必要的配置[mysqld]...bind-address = 0.0.0.0#3台主机的id分别是 1,2,3server-id = 1 binlog-do-db=test #需要记录二进制日志的数据库.如果有多个数据库可用逗号分隔,或者使用多个binlog-do-db选项 #需要同步的数据库 replicate-do-db=test #需要进行同步的数据库.如果有多个数据库可用逗号分隔,或者使用多个binlog-do-db选项 log_bin = /var/log/mysql/mysql-bin.log#这很主要,不然没办法做主从log-slave-updates...
同步数据
我使用的是 innobackupex 同步,也可以mysqldump。
master1 master2 slave1都需要同步
master1 配置
#给master2权限grant replication slave,file on *.* to 'slave'@'192.168.42.29' identified by '123123';#给slave1权限grant replication slave,file on *.* to 'slave'@'192.168.42.33' identified by '123123';stop slave; show master status;+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000007 | 723 | test | |+------------------+----------+--------------+------------------+change master to master_host='192.168.42.29',master_user='slave',master_password='123123',master_log_file='mysql-bin.000008', master_log_pos=267,master_connect_retry=10; #mysql-bin.000008和267是master2的状态 #参数#master_connect_retry默认60秒,重连的时间,如果断开就60秒从试,直到链接上#master_log_pos,master_log_file为复制主机的show master status的值#启动复制start slave;#查看状态show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.42.29 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000008 Read_Master_Log_Pos: 267 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000008 Slave_IO_Running: Yes #显示YES配置成功 Slave_SQL_Running: Yes Replicate_Do_DB: test Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 267 Relay_Log_Space: 410 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 21 row in set (0.00 sec)
master2 配置
#给master2权限grant replication slave,file on *.* to 'slave'@'192.168.42.28' identified by '123123';stop slave; show master status;+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000008 | 267 | test | |+------------------+----------+--------------+------------------+change master to master_host='192.168.42.28',master_user='slave',master_password='123123',master_log_file='mysql-bin.000007', master_log_pos=723; #启动复制start slave;#查看状态show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.42.28 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000007 Read_Master_Log_Pos: 723 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000007 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: test Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 723 Relay_Log_Space: 410 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1
slave1 配置
stop slave; change master to master_host='192.168.42.28',master_user='slave',master_password='123123',master_log_file='mysql-bin.000007', master_log_pos=723; show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.42.28 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000007 Read_Master_Log_Pos: 883 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000007 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 883 Relay_Log_Space: 410 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1
测试
分别在master1,master2 插入数据,在查看3个主机的数据
未解决的问题
当前状态最多能有2台是主
0 0
- mysql 主主+主从笔记
- mysql主从配置笔记
- mysql主从复制笔记
- mysql主从配置学习笔记
- MySql主从数据库配置笔记
- Mysql主从复制配置笔记
- Mysql主从复制安装笔记
- mysql主从复制学习笔记
- mysql主从,主主 centos7
- mysql互为主从复制配置笔记
- mysql互为主从复制配置笔记
- Centos6.3下mysql主从复制笔记
- mysql备忘笔记一(主从复制)
- 1.mysql数据库主从复制部署笔记
- MySQL学习笔记--简单主从复制配置
- mysql主从同步出错解决办法(工作笔记)
- MySQL主从复制服务器(replication)创建笔记
- MySQL主从环境配置(笔记系列)
- 关于cocos2dx 2.x中的音量和音效设置
- [Java代码] JAVA 虚拟机类加载机制和字节码执行引擎
- ubuntu 12.04安装telnet和ssh服务
- CodeForces 618C Constellation
- 64位Ubuntu上编译32位程序操作步骤
- mysql 主主+主从笔记
- day08 广播与服务(二)
- 个人开源项目doMoreDoBetter
- BZOJ 1041: [HAOI2008]圆上的整点
- Remove Duplicates from Sorted Array II
- blog need to read
- SpringMVC系列之(一) 入门实例
- 求图的顶点连通度和边连通度
- QT Creator 代码自动补全---快捷键设定