MYSQL分布式集群使用-主主复制
主主复制,亦可称为互为主从,主主互备或双机热备
1. 配置互为主从 (my.cnf)
2. 查看两台数据库配置情况
3. 建立权限帐户,实现同步
4. 测试同步效果
1. 配置互为主从 (my.cnf)
2. 查看两台数据库配置情况
NO1:Master1(192.168.187.129)的情况
# mysql –u root –p 1234
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001| 107 | test | mysql |
+------------------+----------+--------------+------------------+
NO2:Master2(192.168.187.132)的情况
# mysql –u root –p 1234
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002| 125 | test | mysql |
+------------------+----------+--------------+------------------+
3. 建立权限帐户,实现同步
4. 测试同步效果
在Master1上创建表
mysql -uroot -p1234;
use test;
CREATE TABLE `card` (
`card_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`card_number` varchar(100) DEFAULT NULL COMMENT '卡号',
PRIMARY KEY (`card_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC;
insert into `card`(`card_number`) values ('haha1');
insert into `card`(`card_number`) values ('haha2');
执行完毕后,master2下如果对应的card表已经生成,并且也有相应的数据,证明同步成功,相应在master2上执行任何操作,master1也会相应修改。