http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html
Used variables:
- server-id: The server ID. This value is set by the --server-id option. It is used for replication to enable master and slave servers to identify themselves uniquely.
- auto_increment_increment and auto_increment_offset are intended for use with master-to-master replication, and can be used to control the operation of AUTO_INCREMENT columns. Both variables can be set globally or locally, and each can assume an integer value between 1 and 65,535 inclusive. Setting the value of either of these two variables to 0 causes its value to be set to 1 instead. Attempting to set the value of either of these two variables to an integer greater than 65,535 or less than 0 causes its value to be set to 65,535 instead. Attempting to set the value of auto_increment_increment or auto_increment_offset to a non-integer value gives rise to an error, and the actual value of the variable remains unchanged.
These two variables affect AUTO_INCREMENT column behavior as follows:
One thing that is missing from the above, is how to deal with auto-increments so that you do not get collisions if you add data to both masters at the same time. There is an easy way to deal with this if you are using MySQL 5.0.2 or above.
In the my.cnf file on server1 add:
auto_increment_increment=2
auto_increment_offset=1
In the my.cnf file on server2 add:
auto_increment_increment=2
auto_increment_offset=2
This will make the auto-increment on server1 go, 1,3,5,7,9,etc... and on server2 go, 2,4,6,8,etc... thereby preventing collisions.
server1:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'server2'@'67.15.239.12' IDENTIFIED BY 'Sho6ra5aedoh';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)mysql> CREATE DATABASE testdb;
Query OK, 1 row affected (0.00 sec)
server2:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'server1'@'67.15.239.11' IDENTIFIED BY 'Sho6ra5aedoh';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE DATABASE testdb;
Query OK, 1 row affected (0.00 sec)
server1:/etc/my.cnf
[mysqld]
server-id = 1
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 1
master-host = 67.15.239.12
master-user = server1
master-password = Sho6ra5aedoh
master-connect-retry = 60
replicate-do-db = testdb
log-bin = /var/lib/mysql/mysql-bin.log
binlog-do-db = testdb
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
server2:/etc/my.cnf
[mysqld]
server-id = 2
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 2
master-host = 67.15.239.11
master-user = server2
master-password = Sho6ra5aedoh
master-connect-retry = 60
replicate-do-db = testdb
log-bin = /var/lib/mysql/mysql-bin.log
binlog-do-db = testdb
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
Run:
server2:
mysql> stop slave;
mysql> CHANGE MASTER TO MASTER_HOST='67.15.239.11' , MASTER_USER='server2', MASTER_PASSWORD='Sho6ra5aedoh',MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;
mysql> start slave;
mysql> show slave status \G
mysql> show master status;
server1:
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST='67.15.239.12' , MASTER_USER='server1', MASTER_PASSWORD='Sho6ra5aedoh',MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;
mysql> start slave;
mysql> show master status;
mysql> show slave status \G





1 comments:
Hi
THanks for this article. I am also search the master code for my nokia 3120 mobile & I found the code in unlock free for free
Post a Comment