您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

详解mysql double master的配置方法

2024/3/30 5:57:26发布12次查看
mysql 的 double master 配置假设两台机器  ip 分别为 机器一: 192.168.14.37  机器二:  192.168.14.38 ,服务器 为 linux rhel 5.9
在两台服务器中执行创建用户语句:
mysql:>create user 'repl'@'%' identified by '135246';       -- 创建用户  repl  密码 135246
服务器一执行:
mysql:>grant replication client,replication slave on *.* to 'repl'@'192.168.14.38' identified by '135246';    -- 授权服务器一可以远程访问服务器二
服务器二执行:
mysql:>grant replication client,replication slave on *.* to 'repl'@'192.168.14.37' identified by '135246';     -- 授权服务器二可以远程访问服务器一
验证(根据提示输入密码):
   在服务器一上连接服务器二
mysql -h 192.168.14.38 -u repl -p
在服务器二上连接服务器一
mysql -h 192.168.14.37 -u repl -p
查看 mysql :
首先:vi /etc/my.cnf
  在服务器1, 添加如下内容:
[client]default-character-set=utf8[mysql]default-character-set=utf8[mysqld]server_id = 1log-bincharacter-set-server=utf8#表名不区分大小写lower_case_table_names=1#server_id = 1 # uniquely identify  从为2show master  status
可以得到服务器一和服务器二的  master_log_file  和  master_log_pos 信息,
假设服务器一为    localhost-bin.000004 和 120   服务器二为    localhost-bin.000005 和 667
在服务器一上执行:
stop slave;change master to master_host = '192.168.14.38', master_user = 'repl', master_password = '135246', master_log_file = 'localhost-bin.000004', master_log_pos = 120; start slave;
在服务器二上执行:
stop slave;change master to master_host = '192.168.14.37', master_user = 'repl', master_password = '135246', master_log_file = 'localhost-bin.000005', master_log_pos = 667; start slave;
最后验证主主同步是否成功:
在服务器一 mysql 添加 表 example
mysql:> create database example1 ;use example1;create table example1 (length int);
最后在服务器二查看是否有此数据库,此表,和此条数据.
查看同步状态 :show slave status \g
如果出错,可以看到出错日志。
错误导致同步失败参考mysql slave-skip-errors=all 深层理解
注意: 设置 double master 之前的数据,两个服务器不会同步;
推荐学习:《mysql视频教程》
以上就是详解mysql double master的配置方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product