配置双节点普通复制关系主主同步时,show slave status \G命令两节点连接状态是"yes"。配置的同步库名叫"testzz",从A节点往同步库里插入的数据B节点看不到。操作步骤如下: #创建itcast用户,并设置密码,该用户可在任意主机连接该MySQL服务 CREATE USER 'masterzz_A'@'%' IDENTIFIED WITH mysql_native_password BY '1234'; CREATE USER 'masterzz_B'@'%' IDENTIFIED WITH mysql_native_password BY '1234'; #为 'itcast'@'%' 用户分配主从复制权限 GRANT REPLICATION SLAVE ON *.* TO 'masterzz_A'@'%'; GRANT REPLICATION SLAVE ON *.* TO 'masterzz_B'@'%'; 两台都执行创建数据库 create database testzz character set utf8; 需确认两台ip互通,查看uuid不同 SHOW VARIABLES LIKE "server_uuid"; 修改my.cnf,server-id改为不同的值 #新加 log-bin = /data/GreatSQL/ sync-binlog = 1 binlog_format = mixed binlog-do-db = testzz,androidpnserver binlog-ignore-db = mysql,information_schema,performance_schema auto-increment-increment = 10 auto-increment-offset = 1 replicate-do-db = testzz,androidpnserver replicate-ignore-db = mysql,information_schema,performance_schema log-slave-updates = ON 两台重启服务 systemctl restart greatsql.service 两边先锁表,防止新的数据写入。同时查看master状态。记住 File 和 Position 下面会用到 flush tables with read lock; show master status; masterA执行 change master to master_host='master-B的IP', master_user='master-B创建的账户名', master_password='对应账户密码', master_log_file='master-B的File', master_log_pos=master-B的Position; change master to master_host='192.168.194.161', master_user='masterzz_A', master_password='1234', master_log_file='binlog.000006', master_log_pos=714; change master to master_host='192.168.194.162', master_user='masterzz_B', master_password='1234', master_log_file='binlog.000004', master_log_pos=754; masterB执行 change master to master_host='192.168.194.162', master_user='master-A创建的账户名', master_password='对应账户密码', master_log_file='master-A的File', master_log_pos=master-A的Position; |
4.98 KB, 下载次数: 0, 下载积分: 金币 -1
my.cnf
KAiTO
2024-9-18 14:56:07
| ||
合作电话:010-64087828
社区邮箱:greatsql@greatdb.com