- 浏览: 1053501 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
wenson:
lzjzy520 写道 求 项目完整元代码已经够清楚了,看不懂 ...
使用Spring JavaMail发送邮件总结 -
lzjzy520:
求 项目完整元代码
使用Spring JavaMail发送邮件总结 -
xiejx618:
能提高多大的性能? 不能用数据来说话吧希望你能用jmeter做 ...
利用APR本地库提高Tomcat性能 -
mrwalter:
学习了,挺好用的,局域网内速度很快
ssh远程文件传输命令scp -
wcily123:
不错
ssh远程文件传输命令scp
Version 1.0 Since version 5, MySQL comes with built-in support for master-master replication, solving the problem that can happen with self-generated keys. In former MySQL versions, the problem with master-master replication was that conflicts arose immediately if node A and node B both inserted an auto-incrementing key on the same table. The advantages of master-master replication over the traditional master-slave replication are that you don't have to modify your applications to make write accesses only to the master, and that it is easier to provide high-availability because if the master fails, you still have the other master. I do not issue any guarantee that this will work for you! In this tutorial I will show how to replicate the database exampledb from the server server1.example.com with the IP address 192.168.0.100 to the serverserver2.example.com with the IP address 192.168.0.101 and vice versa. Each system is the slave of the other master and the master of the other slave at the same time. Both systems are running Debian Etch; however, the configuration should apply to almost all distributions with little or no modifications. If MySQL 5.0 isn't already installed on server1 and server2, install it now: server1/server2: apt-get install mysql-server-5.0 mysql-client-5.0 To make sure that the replication can work, we must make MySQL listen on all interfaces, therefore we comment out the line bind-address = 127.0.0.1 in/etc/mysql/my.cnf: server1/server2: vi /etc/mysql/my.cnf Restart MySQL afterwards: server1/server2: /etc/init.d/mysql restart Then check with server1/server2: netstat -tap | grep mysql that MySQL is really listening on all interfaces: server1:~# netstat -tap | grep mysql Afterwards, set a MySQL password for the user root@localhost: server1/server2: mysqladmin -u root password yourrootsqlpassword Next we create a MySQL password for root@server1.example.com: server1: mysqladmin -h server1.example.com -u root password yourrootsqlpassword Now we set up a replication user slave2_user that can be used by server2 to access the MySQL database on server1: server1: mysql -u root -p On the MySQL shell, run the following commands: server1: GRANT REPLICATION SLAVE ON *.* TO 'slave2_user'@'%' IDENTIFIED BY 'slave2_password'; Now we do the last two steps again on server2: server2: mysqladmin -h server2.example.com -u root password yourrootsqlpassword mysql -u root -p GRANT REPLICATION SLAVE ON *.* TO 'slave1_user'@'%' IDENTIFIED BY 'slave1_password'; In the following I will assume that the database exampledb is already existing on server1, and that there are tables with records in it. We will set up replication of exampledb to server2, and afterwards we set up replication of exampledb from server2 to server1. Before we start setting up the replication, we create an empty database exampledb on server2: server2: mysql -u root -p CREATE DATABASE exampledb; Now we set up master-master replication in /etc/mysql/my.cnf. The crucial configuration options for master-master replication are auto_increment_incrementand auto_increment_offset: Let's assume we have N MySQL nodes (N=2 in this example), then auto_increment_increment has the value N on all nodes, and each node must have a different value for auto_increment_offset (1, 2, ..., N). Now let's configure our two MySQL nodes: server1: vi /etc/mysql/my.cnf Search for the section that starts with [mysqld], and put the following options into it (commenting out all existing conflicting options): Then restart MySQL: server1: /etc/init.d/mysql restart Now do the same on server2: server2: vi /etc/mysql/my.cnf server2: /etc/init.d/mysql restart Next we lock the exampledb database on server1, find out about the master status of server1, create an SQL dump of exampledb (that we will import intoexampledb on server2 so that both databases contain the same data), and unlock the database so that it can be used again: server1: mysql -u root -p On the MySQL shell, run the following commands: server1: USE exampledb; The last command should show something like this (please write it down, we'll need it later on): mysql> SHOW MASTER STATUS; Now don't leave the MySQL shell, because if you leave it, the database lock will be removed, and this is not what we want right now because we must create a database dump now. While the MySQL shell is still open, we open a second command line window where we create the SQL dump snapshot.sql and transfer it to server2 (using scp): server1: cd /tmp Afterwards, you can close the second command line window. On the first command line window, we can now unlock the database and leave the MySQL shell: server1: UNLOCK TABLES; On server2, we can now import the SQL dump snapshot.sql like this: server2: /usr/bin/mysqladmin --user=root --password=yourrootsqlpassword stop-slave Afterwards, we must find out about the master status of server2 as well and write it down: server2: mysql -u root -p USE exampledb; SHOW MASTER STATUS; mysql> SHOW MASTER STATUS; Then unlock the tables: server2: UNLOCK TABLES; and run the following command to make server2 a slave of server1 (it is important that you replace the values in the following command with the values you got from the SHOW MASTER STATUS; command that we ran on server1!): CHANGE MASTER TO MASTER_HOST='192.168.0.100', MASTER_USER='slave2_user', MASTER_PASSWORD='slave2_password', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=98; Finally start the slave: server2: START SLAVE; Then check the slave status: server2: SHOW SLAVE STATUS; It is important that both Slave_IO_Running and Slave_SQL_Running have the value Yes in the output (otherwise something went wrong, and you should check your setup again and take a look at /var/log/syslog to find out about any errors): Afterwards, you can leave the MySQL shell on server2: server2: quit Now the replication from server1 to server2 is set up. Next we must configure replication from server2 to server1. To do this, we stop the slave on server1 and make it a slave of server2: server1: mysql -u root -p STOP SLAVE; Make sure that you use the values of the SHOW MASTER STATUS; command that you ran on server2 in the following command: server1: CHANGE MASTER TO MASTER_HOST='192.168.0.101', MASTER_USER='slave1_user', MASTER_PASSWORD='slave1_password', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=783; Then start the slave on server1: server1: START SLAVE; Then check the slave status: server1: SHOW SLAVE STATUS; It is important that both Slave_IO_Running and Slave_SQL_Running have the value Yes in the output (otherwise something went wrong, and you should check your setup again and take a look at /var/log/syslog to find out about any errors): Afterwards you can leave the MySQL shell: quit If nothing went wrong, MySQL master-master replication should now be working. If it isn't, please check /var/log/syslog for MySQL errors on server1 andserver2. Setting Up Master-Master Replication With MySQL 5 On Debian Etch
Setting Up Master-Master Replication With MySQL 5 On Debian Etch
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 10/15/20071 Preliminary Note
2 Installing MySQL 5.0
[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
[...]
tcp 0 0 *:mysql *:* LISTEN 2671/mysqld
server1:~#
FLUSH PRIVILEGES;
quit;
FLUSH PRIVILEGES;
quit;3 Some Notes
quit;4 Setting Up Replication
[...]
[mysqld]
server-id = 1
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 1
master-host = 192.168.0.101
master-user = slave1_user
master-password = slave1_password
master-connect-retry = 60
replicate-do-db = exampledb
log-bin = /var/log/mysql/mysql-bin.log
binlog-do-db = exampledb
relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index
expire_logs_days = 10
max_binlog_size = 500M
[...]
[...]
server-id = 2
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 2
master-host = 192.168.0.100
master-user = slave2_user
master-password = slave2_password
master-connect-retry = 60
replicate-do-db = exampledb
log-bin= /var/log/mysql/mysql-bin.log
binlog-do-db = exampledb
relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index
expire_logs_days = 10
max_binlog_size = 500M
[...]
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000009 | 98 | exampledb | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql>
mysqldump -u root -pyourrootsqlpassword --opt exampledb > snapshot.sql
scp snapshot.sql root@192.168.0.101:/tmp
quit;
cd /tmp
mysql -u root -pyourrootsqlpassword exampledb < snapshot.sql
FLUSH TABLES WITH READ LOCK;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000009 | 783 | exampledb | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql>
mysql> SHOW SLAVE STATUS;
+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+--------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+--------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Waiting for master to send event | 192.168.0.100 | slave2_user | 3306 | 60 | mysql-bin.000009 | 98 | slave-relay.000002 | 235 | mysql-bin.000009 | Yes | Yes | exampledb | | | | | | 0 | | 0 | 98 | 235 | None | | 0 | No | | | | | | 0 |
+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+--------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
1 row in set (0.00 sec)
mysql>
mysql> SHOW SLAVE STATUS;
+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+--------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+--------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Waiting for master to send event | 192.168.0.101 | slave1_user | 3306 | 60 | mysql-bin.000009 | 783 | slave-relay.000002 | 235 | mysql-bin.000009 | Yes | Yes | exampledb | | | | | | 0 | | 0 | 783 | 235 | None | | 0 | No | | | | | | 0 |
+----------------------------------+---------------+-------------+-------------+---------------+------------------+---------------------+--------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
1 row in set (0.00 sec)
mysql>
5 Links
评论
这不是山寨,这是原版收藏,最后面有原文地址。
发表评论
-
mysql主从同步报错故障处理总结 [数据库技术]
2015-12-14 13:37 4562前言 在发生故障切换后,经常遇到的问题就是同步报错,数据 ... -
MySQL Replication 主从同步原理及配置
2014-11-07 11:35 3268MySQL的Replication是一种多个MySQL的数据 ... -
关于MySQL 查询表数据大小的总结
2014-09-18 18:14 5049一:关于mysql表数据大小 我们知道mysql存储数据文 ... -
MySQL使用Event定时执行任务
2013-11-07 10:56 7131一、基本概念 mysql5 ... -
MySQL grant 语法的详细解析(帐号权限管理)
2013-10-09 16:31 1441记录一下mysql grant的一些用法。MySQL数据库 ... -
MySQL函数不能创建的解决方法
2013-09-18 11:34 1242在使用MySQL数据库时,有时会遇到MySQL函数不能创建的 ... -
mysql里的SUBSTRING
2013-09-16 11:23 1325截取字符串 substring(str, pos) subst ... -
MYSQL EVENT 使用手册
2012-10-15 19:28 1048一、前言 自MySQL5.1.6起,增加了一个非常有特 ... -
备忘:mysql备份的帐号权限
2012-01-13 04:55 1959mysql备份的帐号权限,只需要:show databases ... -
怎样用命令查看Mysql数据库大小?
2011-12-14 01:51 53671、进去指定schema 数据库(存放了其他的数据库的信息) ... -
解决InnoDB出现“the table is full”的问题
2011-12-09 02:40 1741最近数据库数据量及访问频率比较大的两个表出现了the tabl ... -
mysql从服务器出现的错误解決方法:Slave_SQL_Running: No(主-从)
2011-10-19 00:16 25571、出现错误提示、 Slave I/O: ... -
spring+atomikos+JTA多數據源配置
2011-05-06 22:54 2614spring+atomikos+JTA多數據源配置中,需要注意 ... -
mysql innodb数据库的优化
2011-01-12 19:48 3161硬件概況: linux服务器 ... -
Mac OS X 中mysql的配置文件my.cnf的位置
2010-10-10 21:33 24153OS X 系统安装的mysql默认是不用my.cnf配置文件的 ... -
Mysql双机备份方案
2010-06-13 13:55 2897运行环境: 虚拟机安装的是CentOS5 Mysql版 ... -
监控sql执行性能的工具:jdbmonitor
2010-02-16 01:18 1931一个用来监控sql执行性能的工具:jdbmonitor ... -
使用mysqlsla分析mysql日志
2009-12-12 03:53 2697mysqlsla是hackmysql.com推出的一款My ... -
持久层的数据库锁控制
2009-12-05 09:51 4054网站最近并发访问量增多,log常一旦抛出以下异常: Caus ... -
在linux里定时备份mysql
2009-11-26 01:56 17991、导出远程mysql数据库到本地成为sql文件: file ...
相关推荐
5. **配置灵活**:用户可以通过配置文件灵活设定同步规则,比如选择特定的数据库、表进行同步,或者设置忽略某些字段,满足不同场景的需求。 6. **易于集成**:Go-mysql-schema-sync可以方便地与持续集成/持续部署...
MySQL 双机热备同步是指两个 MySQL 服务器之间的实时数据同步,通过配置主从关系和双向同步机制,实现数据的实时备份和热备。下面将详细介绍 MySQL 双机热备同步的配置步骤和原理。 主从关系同步 在 MySQL 中,...
在MySQL的高可用性解决方案中,MHA(Master High Availability)是一个不可忽视的重要工具。本文将深入探讨MHA的两个核心组件——`mha4mysql-manager`和`mha4mysql-node`,以及它们在`0.58`版本中的应用。 MHA,...
MySQL的主从复制和半同步复制是数据库集群中常见的高可用性和数据冗余策略,能够保证数据的一致性并提供故障恢复能力。本文将详细解释这两种复制方式的原理、配置步骤以及优缺点。 **一、MySQL主从复制** MySQL...
MySQL的主从复制是数据库高可用性和数据冗余的一种常见实现方式,它允许数据从一个服务器(主服务器)同步到一个或多个其他服务器(从服务器)。这种架构在处理大量读取操作、提供故障切换能力以及分布式系统中尤其...
不过,正确配置和管理MHA需要对MySQL复制机制有深入理解,同时也需要注意监控和日志管理,以确保在发生问题时能够快速定位和解决。在实际生产环境中,结合其他监控工具和自动化流程,可以进一步提升MySQL集群的稳定...
**MySQL高可用解决方案MHA(Master High Availability)** MySQL作为广泛应用的关系型数据库系统,其高可用性和稳定性至关重要。为了确保数据库服务的连续性,开发者和运维人员常常采用各种高可用解决方案,其中MHA...
MHA(Master High Availability)是针对MySQL的一种高可用性管理工具,它通过监控MySQL主从复制状态并在主服务器故障时自动切换到备用节点,从而实现系统的不间断运行。本文将详细介绍MHA的原理、安装过程以及如何...
MHA的基础是MySQL的主从复制机制。在正常情况下,主服务器处理写操作并将其记录到二进制日志,从服务器通过读取并应用这些日志来保持与主服务器同步。MHA在检测到主服务器失败后,会选择一个最近且同步良好的从库...
在Windows环境下进行MySQL单机主-从同步复制是一项高级配置技术,主要用于实现数据冗余、负载均衡或数据分发。本文将深入解析这一过程的关键步骤和技术细节,帮助读者理解并实施MySQL主从复制。 ### 复制基本原理 ...
- 复制Master服务器的MySQL安装文件到一个新的位置,并进行相应的配置更改,如端口号、基于目录的设置(`basedir`和`datadir`)以及服务名称。 - 在Slave服务器的配置文件中,同样配置`log-bin`以记录本地的更改,...
`sync-mysql-schema-data-master`这个文件名可能是项目源代码的主分支,包含该工具的源代码和资源文件。通过阅读和研究这个项目的源代码,开发者可以进一步学习如何在Go中实现类似的数据库同步功能。 总的来说,...
这样,主服务器上的所有更改都会被记录下来,并且可以通过复制机制同步到从服务器上。在配置文件/etc/***f中,需要设置server-id来标识集群中的唯一节点,并开启binlog功能。之后,重启MySQL服务以使配置生效。 ...
MySQL主从复制是一种异步复制机制,主要分为三个角色:主服务器(Master)、从服务器(Slave)和复制线程。主服务器负责处理客户端的写请求,并将更改记录到二进制日志(binlog)。从服务器通过IO线程拉取主服务器的...
"MHA for MySQL Node 0.58" 是一个专门针对MySQL数据库系统设计的高可用性管理工具,全称为“Master High Availability for MySQL”。这个版本0.58的压缩包(tar.gz格式)提供了在分布式环境中确保MySQL主从复制的...
- **日志同步**:为了保证数据一致性,建议使用半同步复制或至少有良好的主从延迟控制机制。 - **监控和报警**:配合其他监控工具,如Nagios、Zabbix等,实时了解MHA的运行状态和故障信息。 - **测试和演练**:定期...
总的来说,解决`ReplicationDriver`在MySQL主从复制中的问题需要对MySQL复制机制、JDBC驱动和Java编程有深入理解。通过阅读和分析提供的源码,可以定制适合特定需求的解决方案,以应对各种复杂的网络环境和性能挑战...
MySQL中的复制机制是为了保证数据的一致性与高可用性。其中涉及到异步复制、同步复制、半同步复制以及无损复制等不同的复制类型,每种复制方式各有特点和适用场景。 首先,异步复制(Asynchronous Replication)是...
MySQL Schema Sync是一个用于同步MySQL数据库表结构的工具,它能够帮助开发者在多个数据库实例之间保持数据表结构的一致性。这个工具特别适用于那些需要在开发、测试和生产环境之间进行数据库迁移或者版本控制的场景...