mysql master 配置_MySQL双Master配置的方法详解
刚刚抽空做了一下MYSQL 的主主同步。把步骤写下来,至于会出现的什么问题,以后随时更新。这里我同步的数据库是TEST1、环境描述。主机:192.168.0.231(A)主机:192.168.0.232(B)MYSQL 版本为5.1.212、授权用户。A:mysql> grant replication slave,file on *.* to 'repl1'@'192.168.0.232' identifiedby '123456';Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)B:mysql> grant replication slave,file on *.* to 'repl2'@'192.168.0.231' identifiedby '123456';Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)然后都停止MYSQL 服务器。3、配置文件。在两个机器上的my.cnf里面都开启二进制日志 。A:user = mysqllog-bin=mysql-binserver-id = 1binlog-do-db=testbinlog-ignore-db=mysqlreplicate-do-db=testreplicate-ignore-db=mysqllog-slave-updatesslave-skip-errors=all
skip-name-resolvesync_binlog=1auto_increment_increment=2auto_increment_offset=1B:user = mysqllog-bin=mysql-binserver-id = 2binlog-do-db=testbinlog-ignore-db=mysqlreplicate-do-db=testreplicate-ignore-db=mysqllog-slave-updatesslave-skip-errors=all
skip-name-resolvesync_binlog=1auto_increment_increment=2auto_increment_offset=2至于这些参数的说明具体看手册。红色的部分非常重要,如果一个MASTER 挂掉的话,另外一个马上接管。紫红色的部分指的是服务器频繁的刷新日志。这个保证了在其中一台挂掉的话,日志刷新到另外一台。从而保证了数据的同步 。4、重新启动MYSQL服务器。在A和B上执行相同的步骤[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe &[1] 4264[root@localhost ~]# 071213 14:53:20 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'./usr/local/mysql/bin/mysqld_safe: line 366: [: -eq: unary operator expected071213 14:53:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data5、进入MYSQL的SHELL。A:mysql> flush tables with read lock\GQuery OK, 0 rows affected (0.00 sec)mysql> show master status\G*************************** 1. row ***************************File: mysql-bin.000007Position: 528Binlog_Do_DB: testBinlog_Ignore_DB: mysql1 row in set (0.00 sec)B:mysql> flush tables with read lock;Query OK, 0 rows affected (0.00 sec)mysql> show master status\G*************************** 1. row ***************************File: mysql-bin.000004Position: 595Binlog_Do_DB: testBinlog_Ignore_DB: mysql1 row in set (0.00 sec)然后备份自己的数据,保持两个机器的数据一致。方法很多。完了后看下一步。6、在各自机器上执行CHANGE MASTER TO命令。A:mysql> change master to-> master_host='192.168.0.232',-> master_user='repl2',-> master_password='123456',-> master_log_file='mysql-bin.000004',-> master_log_pos=595;Query OK, 0 rows affected (0.01 sec)mysql> start slave;Query OK, 0 rows affected (0.00 sec)B:mysql> change master to-> master_host='192.168.0.231',-> master_user='repl1',-> master_password='123456',-> master_log_file='mysql-bin.000007',-> master_log_pos=528;Query OK, 0 rows affected (0.01 sec)mysql> start slave;Query OK, 0 rows affected (0.00 sec)7、查看各自机器上的IO进程和 SLAVE进程是否都开启。A:mysql> show processlist\G*************************** 1. row ***************************Id: 2User: replHost: 192.168.0.232:54475db: NULLCommand: Binlog DumpTime: 1590State: Has sent all binlog to slave; waiting for binlog to be updatedInfo: NULL*************************** 2. row ***************************Id: 3User: system userHost:db: NULLCommand: ConnectTime: 1350State: Waiting for master to send eventInfo: NULL*************************** 3. row ***************************Id: 4User: system userHost:db: NULLCommand: ConnectTime: 1149State: Has read all relay log; waiting for the slave I/O thread to update itInfo: NULL*************************** 4. row ***************************Id: 5User: rootHost: localhostdb: testCommand: QueryTime: 0State: NULLInfo: show processlist4 rows in set (0.00 sec)B:mysql> show processlist\G*************************** 1. row ***************************Id: 1User: system userHost:db: NULLCommand: ConnectTime: 2130State: Waiting for master to send eventInfo: NULL*************************** 2. row ***************************Id: 2User: system userHost:db: NULLCommand: ConnectTime: 1223State: Has read all relay log; waiting for the slave I/O thread to update itInfo: NULL*************************** 3. row ***************************Id: 4User: rootHost: localhostdb: testCommand: QueryTime: 0State: NULLInfo: show processlist*************************** 4. row ***************************Id: 5User: repl2Host: 192.168.0.231:50718db: NULLCommand: Binlog DumpTime: 1398State: Has sent all binlog to slave; waiting for binlog to be updatedInfo: NULL4 rows in set (0.00 sec)如果红色部分没有出现,检查DATA目录下的错误文件。8、释放掉各自的锁,然后进行插数据测试。mysql> unlock tables;Query OK, 0 rows affected (0.00 sec)插入之前两个机器表的对比:A:mysql> show tables;+----------------+| Tables_in_test |+----------------+| t11_innodb || t22 |+----------------+B:mysql> show tables;+----------------+| Tables_in_test |+----------------+| t11_innodb || t22 |+----------------+从A机器上进行插入A:mysql> create table t11_replicas-> (id int not null auto_increment primary key,-> str varchar(255) not null) engine myisam;Query OK, 0 rows affected (0.01 sec)mysql> insert into t11_replicas(str) values-> ('This is a master to master test table');Query OK, 1 row affected (0.01 sec)mysql> show tables;+----------------+| Tables_in_test |+----------------+| t11_innodb || t11_replicas || t22 |+----------------+3 rows in set (0.00 sec)mysql> select * from t11_replicas;+----+---------------------------------------+| id | str |+----+---------------------------------------+| 1 | This is a master to master test table |+----+---------------------------------------+1 row in set (0.00 sec)现在来看B机器:mysql> show tables;+----------------+| Tables_in_test |+----------------+| t11_innodb || t11_replicas || t22 |+----------------+3 rows in set (0.00 sec)mysql> select * from t11_replicas;+----+---------------------------------------+| id | str |+----+---------------------------------------+| 1 | This is a master to master test table |+----+---------------------------------------+1 row in set (0.00 sec)现在反过来从B机器上插入数据:B:mysql> insert into t11_replicas(str) values('This is a test 2');Query OK, 1 row affected (0.00 sec)mysql> select * from t11_replicas;+----+---------------------------------------+| id | str |+----+---------------------------------------+| 1 | This is a master to master test table || 2 | This is a test 2 |+----+---------------------------------------+2 rows in set (0.00 sec)我们来看AA:mysql> select * from t11_replicas;+----+---------------------------------------+| id | str |+----+---------------------------------------+| 1 | This is a master to master test table || 2 | This is a test 2 |+----+---------------------------------------+2 rows in set (0.00 sec)好了。现在两个表互相为MASTER。
本文标题: MySQL双Master配置的方法详解
本文地址: http://www.cppcns.com/shujuku/mysql/96842.html
mysql master 配置_MySQL双Master配置的方法详解相关推荐
- mysql命令去重_mysql去重的两种方法详解及实例代码
mysql去重 方法一: 在使用MySQL时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数, ...
- java 修改mysql数据库表结构_MYSQL数据库表结构优化方法详解
摘要:这篇MySQL栏目下的"MYSQL数据库表结构优化方法详解",介绍的技术点是"mysql数据库表结构.MySQL数据库.数据库表结构.MySQL.据库表结构.数据库 ...
- mysql-bin 查看_Mysql Binlog数据查看的方法详解
binlog介绍 binlog,即二进制日志,它记录了数据库上的所有改变. 改变数据库的SQL语句执行结束时,将在binlog的末尾写入一条记录,同时通知语句解析器,语句执行完毕. binlog格式 ...
- mysql insert into as_mysql insert into select使用方法详解
mysql insert into select使用方法详解2017-11-22 15:47 我们先来看看mysql insert into select的语法规则. INSERT [LOW_PRIO ...
- pdo mysql fetchall_PDO中获取结果集之fetchAll()方法详解
fetchAll()方法是获取结果集中的所有行,返回一个包含结果集中所有行的二进制数组!大理石机械构件维修厂家 那么在上一篇<PDO中获取结果集之fetch()方法详解>中,我们介绍了fe ...
- 给mysql 授权 命令_mysql中授权命令grant用法详解:
mysql中授权命令grant用法详解: mysql中可以给你一个用户授予如select,insert,update,delete等其中的一个或者多个权限,主要使用grant命令,用法格式为: gra ...
- mysql escape关键字_MySQL中ESCAPE关键字的用法详解
MySQL转义 转义即表示转义字符原来的语义,一个转义字符的目的是开始一个字符序列,使得转义字符开头的该字符序列具有不同于该字符序列单独出现时的语义. MySQL中,转义字符以"\" ...
- 连接mysql所必须参数_数据库连接参数使用方法详解
在设计数据库应用程序的时候,经常需要将一些信息从程序中独立出来,以保证程序的可移植性.其中最重要的信息就是数据库的连接参数. 在Delphi中,获得正确的数据库连接参数的方法十分简单,你只需要建立一个 ...
- mysql linux文件_MySQL在Linux系统下配置文件详解
在日常的的开发过程中接触到了SQLServer和MySQL数据库的操作性问题,可能是以前接触的都是SQL Server,才开始接触MySQL,总感觉使用MySQL没有使用SQLserver那么顺手,一 ...
最新文章
- 八、进程调度的时机、切换与过程,调度方式
- lua 访问oracle,lua语言数据库访问 - Lua教程
- 树莓派2代B model 上手初体验,不用显示器,Python GPIO 点亮一颗LED
- 虚拟机Ubuntu18.04 root下 连接 windows 中 winScp
- delphi listview 添加数据 慢_Delphi 二十四岁, Delphi 10.3.1 发布
- 从ASM拷贝文件的方法
- 【翻转整数考虑溢出】LeetCode 7. Reverse Integer
- 对话周鸿祎:从程序员创业谈起
- 折腾!在树莓派上运行DOS
- Inno Setup打包的exe程序加上【unins.exe】卸载程序
- 最新版cleanmymac4.11.3专业的Mac清理软件
- 微软预览word_如何解决Microsoft Word中的打印问题
- 微信公众平台开发-消息管理-发送客服消息
- 僵尸国度.Z.Nation
- 八、PyQt5绘图技术
- 直播预告 | ICLR专场一
- DES算法和MAC算法总结
- Linux 链路聚合之bond和team
- 对计算机应用技术的认识和我感想,信息技术培训心得体会范文大全
- 免费的html 音乐,21 个免费的网页和博客音乐播放器
热门文章
- 数据结构:下列选项中,不可能是快速排序第2趟排序结果的是(2019年全国试题10)
- 牛客网_PAT乙级1002_数字分类 (20)
- 基本的Socket通信
- 【含义解析】%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %m%n
- 关于sscanf与结构体不能联用的问题
- eclipse怎么导入一个Java项目(莫要错过,最详细教程!)
- (*长期更新)软考网络工程师学习笔记——Section 14 Linux服务器配置
- android平板2018,荣耀平板5和ipad2018哪个值得买 荣耀平板5和ipad2018哪个好
- java中字符串的操作_java中字符串的操作
- sql的加减乘除运算_SQL简单查询语、运算符学习和练习