Mysql主主复制(二)

2015-01-23 22:04:41 · 作者: · 浏览: 12
/mysqldb/oracle11g.com.pid
plugin-dir=/usr/local/mysql/lib/plugin
socket=/tmp/mysql.sock

# ----master-----#
server_id=1
log-bin=/cifpay/mysql-bin.log
binlog-ignore-db=mysql
auto-increment-increment=2
auto-increment-offset=1
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION ================ MASTER 2
[mysql@master2~]$ cat /usr/local/mysql/my.cnf # For advice on how to change settings please see
[mysqld]
port=3308
basedir=/usr/local/mysql
datadir=/cifpay/mysqldb
log-error=/cifpay/mysqldb/dominic.mysql1.err
pid-file=/cifpay/mysqldb/dominic.mysql1.pid
plugin-dir=/usr/local/mysql/lib/plugin
# ----master 2 -------#
server-id=2
read_only=TURE
binlog-ignore-db=mysql
#log_slave_updates=1
log-bin=/cifpay/mysql-bin.log
auto-increment-increment=2
auto-increment-offset=2
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

重启动 MASTER 1、MASTER 2 数据库,使配置生效:
MASTER 1 : mysql> change master to -> MASTER_HOST='192.168.0.167', -> MASTER_USER='copy1', --用户不要一样 -> MASTER_PASSWORD='123456', -> MASTER_LOG_FILE='mysql-bin.000002', --来自 master 2 -> MASTER_LOG_POS=753, --来自 master 2 -> MASTER_PORT=3308; Query OK, 0 rows affected, 2 warnings (0.08 sec)
mysql> start slave; Query OK, 0 rows affected (0.01 sec) mysql> SHOW SLAVE STATUS \G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.0.167 Master_User: copy1 Master_Port: 3308 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 753 Relay_Log_File: oracle11g-relay-bin.000002 Relay_Log_Pos: 283 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: 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: 753 Relay_Log_Space: 460 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 Master_UUID: 9b6fc45b-81b3-11e4-95f4-0800273e24cb Master_Info_File: /cifpay/mysqldb/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.00 sec)
MASTER 2
mysql> CHANGE MASTER TO -> MASTER_HOST='192.168.0.186', -> MASTER_USER='copy2', -> MASTER_PASSWORD='123456', -> MASTER_LOG_FILE='mysql-bin.000005', --来自master 1 -> MASTER_LOG_POS=216, --来自master 1 -> MASTER_PORT=3308; ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first mysql> STOP SLAVE; Query OK, 0 rows affected (0.03 sec)
mysql> CHANGE MASTER TO -> MASTER_HOST='192.168.0.186', -> MASTER_USER='copy2', -> MASTER_PASSWORD='123456', -> MASTER_LOG_FILE='mysql-bin.000005', -> MASTER_LOG_POS=216, -> MASTER_PORT=3308; Query OK, 0 rows affected, 2 warnings (0