您的位置:首页 > 数据库 > MySQL

mysql主主复制

2016-03-04 17:19 344 查看

主主复制原理:


在这篇文章( http://www.cnblogs.com/whereareyoufrom/p/5240380.html )中讲解主从复制的原理,而主主复制的原理更加简单,只需要将主从复制中master的配置操作再在slave中配置一遍,将slave的配置操作在master中配置一遍即可。


配置:

salve配置(将slave配置成master):
1.修改slave mysql配置文件,加入如下内容

server-id=2
log-bin=mysqlbinlog  #开始binlog,binlog文件命名为mysqlbinlog
binlog_format=fixed  #binlog格式

binlog-do-db=mydata
#binlog-ignore-db=xxx
auto-increment-offset=2
auto-increment-increment=2

2.创建binlog操作用户

>>> create user replicator@'%' identified by 'xxxxxx';
>>> grant replication slave on *.* to 'replicator'@'%' identified by 'xxxxxx';
>>> flush privileges;

3.查看binlog文件名和文件指针位置

>>> show master status;
+--------------------+----------+--------------+------------------+
| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mysqlbinlog.000001 |      245 | mydata       |                  |
+--------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

master 配置(将master配置成slave):
1.修改master 配置文件(重启mysql)

replicate-do-db=mydata

2.配置binlog文件信息

>>> change master to
master_host='192.168.252.18',
master_user='replicator',
master_password='xxxxx',
master_log_file='mysqlbinlog.000001',
master_log_pos='245';
>>> start slave;
>>> show slave status;
MariaDB [mydata]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.252.18
Master_User: replicator
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysqlbinlog.000001
Read_Master_Log_Pos: 1157
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 1078
Relay_Master_Log_File: mysqlbinlog.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: mydata
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1157
Relay_Log_Space: 1374
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
1 row in set (0.00 sec)

ERROR: No query specified
slave 两个线程启动正确。o啦
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: