Wednesday, July 28, 2010

How To MySQL Replication

Hi there this time as usual I just play with another server at work, and replicating is really simple and easy check the steps bellow
a) You must have 2 servers running MySQL ( I like MySQL-Max )
b) There will be 2 configurations one p/ server ( Master ) and one per client ( Client :P ).

—- >Server / Master Side:
1) Edit /etc/hosts.allow and add this line ( you MUST change this IP’s for yours !! )
mysql: 192.168.10.70 192.168.10.13
2) Edit my.cnf …. In my case located at: /etc/my.cnf
* I’m going to show just a what you need the my.cnf file contains much more info.

####### Comment this lines:
bind-address = xxx.xxx.xxx.xxx
skip-networking
####### Make sure this lines exists in the [mysqld] Section:
log-bin=mysql-bin
server-id = 1

3) Now lets move to mysql using a power user like root xD

mysql> GRANT ALL ON databasename.* TO repl@'%' IDENTIFIED BY 'put_some_pass_here';
mysql> FLUSH PRIVILEGES;
mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO repl@'%' IDENTIFIED BY 'put_some_pass_here';

4) restart MySQL service
—- >Client Side:
5) Edit my.cnf …. In my case located at: /etc/my.cnf
* I’m going to show just a what you need the my.cnf file contains much more info.

#### Add this lines or modify them
log-bin=SOME_NAME-relay-bin
server-id = 2
#### This number increases when you add more than one SLAVE os CLIENT to the MASTER server
master-host = 192.168.50.8
#### Put the Hostname or IP from your MASTER server
master-user = repl
master-password = put_some_pass_here
replicate-do-db=databasename

6) restart the service
7) done !! all data will be Replicated.
8) Troubleshooting
Master:
mysql> SHOW GRANTS FOR repl;
mysql> SHOW MASTER LOGS \G
mysql> SHOW BINARY LOGS;
mysql> SHOW MASTER STATUS;
mysql> RESET MASTER ---> ( CAUTON !!! )
-------- SLAVE:
mysql> SHOW SLAVE STATUS;
mysql> STOP SLAVE;
mysql> START SLAVE;
mysql> RESET SLAVE; ---> ( CAUTON !!! )
---------------------------------------------
mysql> LOAD DATA FROM MASTER;
ERROR 1219 (HY000): Error running query on master: Access denied; you need the RELOAD privilege for this operation
////////// IF YOU SEE THIS in SLAVE side .... Type This NEXT in the MASTER SERVER:
mysql> GRANT RELOAD on *.* to repl@'%' identified by 'your_password';
OR
mysql> GRANT SUPER on *.* to repl@'%' identified by 'your_password';

No comments:

Post a Comment