If you need master-master replication for your MySQL server. This example is for Centos 6 x64 but on other Linux OS the process is similar.
For example we have two following servers with IPs:
1.1.1.1 SERVER_A
2.2.2.2 SERVER_B
yum -y install mysql-server
server-id = 1
bind-address = 1.1.1.1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = database_for_replication
#replicate-do-table = database_for_replication.table_for_replication (You can replicate only some table(s))
on SERVER_B:server-id = 2
bind-address = 2.2.2.2
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = database_for_replication
After changes – restart mysql on both servers /etc/init.d/mysql restartgrant all privileges on *.* to replication_username@'%' identified by "some_password";
flush privileges;
show master status;
the result will be similar to:
+-------------------+----------+---------------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+---------------------------+------------------+
| mysqld-bin.000005 | 49572095 | database_for_replication | |
+-------------------+----------+---------------------------+------------------+
1 row in set (0.00 sec)
REMEMBER THIS RESULT, YOU'LL NEED IT IN STEP 5
slave stop;
change master to master_host='1.1.1.1', master_user='replication_username', master_password='some_password', master_log_file='mysqld-bin.000005', master_log_pos=49572095;
slave start;
show master status;
the result will be similar to:
+-------------------+----------+---------------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+---------------------------+------------------+
| mysqld-bin.000001 | 98748451 | database_for_replication | |
+-------------------+----------+---------------------------+------------------+
1 row in set (0.00 sec)
REMEMBER THIS RESULT, YOU'LL NEED IT IN STEP 7
slave stop;
change master to master_host='2.2.2.2', master_user='replication_username', master_password='some_password', master_log_file='mysqld-bin.000001', master_log_pos=98748451;
slave start;
THAT’S IT, YOUR MYSQL CLUSTER READY