Wednesday, April 29, 2009

Setup Mysql Replication Between Linux(master) & Windows XP(Slave)

Step 1 - Configure the Master Server


First we have to edit /etc/mysql/my.cnf. We have to enable networking for MySQL, and MySQL should listen on all IP addresses, therefore we comment out these lines (if existant):


#skip-networking


#bind-address            = 127.0.0.1


 Furthermore we have to tell MySQL for which database it should write logs (these logs are used by the slave to see what has changed on the master), 


which log file it should use, and we have to specify that this MySQL server is the master. We want to replicate the database exampledb, so 


we put the following lines into/etc/mysql/my.cnf:


server-id               = 1


log_bin                 = /var/log/mysql/mysql-bin.log


binlog_do_db            = exampledb


 


 Then we restart MySQL:


/etc/init.d/mysql restart


Then we log into the MySQL database as root and create a user with replication privileges:


 


mysql -u root -p


Enter password:


 


Now we are on the MySQL shell.


mysql>GRANT REPLICATION SLAVE ON *.* TO ’slave_user’@'%’ IDENTIFIED BY ‘<some_password>’; (Replace<some_password> with a real password!) 


mysql>FLUSH PRIVILEGES;


 


Next (still on the MySQL shell) do this:


 mysql>USE exampledb;


mysql>FLUSH TABLES WITH READ LOCK;


mysql>SHOW MASTER STATUS;


 


The last command will show something like this:


 +—————+———-+————–+——————+


| File          | Position | Binlog_do_db | Binlog_ignore_db |


+—————+———-+————–+——————+


| mysql-bin.006 | 183      | exampledb    |                  |


+—————+———-+————–+——————+


1 row in set (0.00 sec)


 


Write down this information, we will need it later on the slave!


Then leave the MySQL shell:


 


mysql>quit;


 


Step 2 - Configure the Slave Server(Windows XP)





Edit the c:\program files\mysql\mysql server 5.0\my.ini 


server-id=2



master-host=db01.yourdomain.net (or IP address)
master-port=3306
master-user=slave_user
master-password=password

Step 3 - Restart Mysql Service 


goto> Control Panel>Administrative Tools>Services>Mysql 


Restart Service


mysql > Stop slave;


mysql>CHANGE MASTER TO MASTER_HOST=’192.168.10.175′, MASTER_USER=’slave_user’, MASTER_PASSWORD=’password’,MASTER_LOG_FILE=’mysql-bin.000008′,MASTER_LOG_POS=98;


mysql > Start slave;

No comments:

sanjay's shared items

My Blog List