MySql master to master replication
Server 1: /etc/my.sql
#replication server-id=1 log-bin=mysql-bin
#information for becoming slave. master-host = master-user = replication master-password = slave master-port = 3306
Server 2: /etc/my.sql
#replication server-id=2 log-bin=mysql-bin
#information for becoming slave. master-host = master-user = replication master-password = slave master-port = 3306
Restart /etc/init.d/mysql restart on both servers.
Then run the following SQL on… server 1:
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST=’10.253.15.15′,MASTER_USER=’replication’,MASTER_PASSWORD=’slave’;
START SLAVE;
GRANT ALL PRIVILEGES ON *.* TO ‘replication’@” identified by ‘slave’;
server 2:
CHANGE MASTER TO MASTER_HOST=’10.253.65.221′,MASTER_USER=’replication’,MASTER_PASSWORD=’slave’;
STOP SLAVE;
START SLAVE;
GRANT ALL PRIVILEGES ON *.* TO ‘replication’@” identified by ‘slave’;
Later you can check master and slave statuses:
show slave status\G;
show master status\G;
–
Out of sync – Last time helped:
On master (or in server that have correct data):
mysql> SHOW MASTER STATUS;
Output should be somethink like that:
+——————+————————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+————————–+——————+
| mysql-bin.000001 | 3400 | | mysql |
+——————+————————–+——————+
1 row in set (0.00 sec)
Write down the filename and log position for use on the original Master server.
In mysql that is out of sync:
mysql> stop slave;
mysql> CHANGE MASTER TO MASTER_LOG_FILE=’[File written down]‘, MASTER_LOG_POS=[position];
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS\G
Kui on tarvis ignoreerida mõnda tabelit. S.t slaves saab ütelda, et seda tabelit sellest andmebaasist siia ära replitseeri
replicate-wild-ignore-table=dbname%.tablename%
Master andmebaasis tasub tabelid lukustada, ajaks kuni te infot slave(sse) viite – UNLOCK TABLES;
Lihtsalt hint endale. Peaks slaves olles olema võimalik ka datat importida, pole proovinud – LOAD DATA FROM MASTER;
