MySQL master slave replication of multiple databases

On the master server :

We have to enable networking ;if it is skipped. Enable binary logging and start a binary log of all databases

Add the following to the my.cnf file and restart MySQL


server-id = 1
log-bin=mysql-bin
binlog-do-db=gnusys_kb
binlog-do-db=gnusys_wiki
binlog-do-db=powerdns

create a user on the master with replication slave privileges on all databases from the slaves IP address

GRANT REPLICATION SLAVE ON *.* TO '*****************'@'ip.ip.ip.ip' IDENTIFIED BY '********';

The next step is to have identical data on both master and slave server .This can be accomplished by preventing all writes on the master for some time and take a snapshot of the databases on the master using mysqldump and restore all of them on the slave

FLUSH TABLES WITH READ LOCK;

Keep this prompt running;inoder that the lock is active

mysqldump db1 –lock-all-tables > db1.june14.sql
mysqldump gnusys_kb –lock-all-tables > powerdns.june14.sql
………………


and on the slave server restore the databases.

The next step is to get some vital information from the master to initiate replication on the slave.On masters mysql prompt run

SHOW MASTER STATUS;
+------------------+----------+---------------------------------------------------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+---------------------------------------------------------------+------------------+
| mysql-bin.000001 | 1547443 | gnusys_kb,gnusys_wiki,powerdns,gnusys_kb,gnusys_wiki,powerdns | |
+------------------+----------+---------------------------------------------------------------+------------------+
1 row in set (0.00 sec)

add the following to the my.cnf of the slave server

#Mysql slave settings
server-id = 2
master-host=174.136.4.248
master-user=******************
master-password=*********
master-connect-retry=60
replicate-do-db=gnusys_kb
replicate-do-db=gnusys_wiki
replicate-do-db=powerdns

Restart slave mysql

Now we remote the write lock on the master.On masters mysql prompt which we kept running

UNLOCK TABLES;

On the slaves mysql prompt run the following

SLAVE STOP;

CHANGE MASTER TO MASTER_HOST='ip.ip.ip.ip', MASTER_USER='*********',MASTER_PASSWORD='*****', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;

START SLAVE;
quit;

Thats it!.

The status of master can be known from

SHOW MASTER STATUS;

and slave can be known by

SHOW SLAVE STATUS;

Share and Enjoy:
  • Digg
  • Mixx
  • del.icio.us
  • StumbleUpon
  • Facebook
  • TwitThis
  • Technorati
  • Google

2 Responses to “MySQL master slave replication of multiple databases”

  1. discount nfl jerseys Says:

    Jack Lambert Stitched Jerseys
    Ben Roethlisberger Stitched Jerseys
    Hines Ward Stitched Jerseys
    Dan Fouts Stitched Jerseys
    Philip Rivers Stitched Jerseys
    Ronnie Lott Stitched Jerseys
    Michael Crabtree Stitched Jerseys
    Joe Montana Stitched Jerseys
    Frank Gore Stitched Jerseys
    Patrick Willis Stitched Jerseys
    Jerry Rice Stitched Jerseys
    Aaron Curry Stitched Jerseys
    Eric Dickerson Stitched Jerseys
    Chris Long Stitched Jerseys
    Sam Bradford Stitched Jerseys
    Warren Sapp Stitched Jerseys
    Vince Young Stitched Jerseys
    Clinton Portis Stitched Jerseys

  2. cowboys jersey Says:

    Bill Bates Jersey
    DeMarcus Ware Jersey
    Dez Bryant Jersey
    Emmitt Smith Jersey
    Felix Jones Jersey
    Jason Witten Jersey
    Jay Novacek Jersey
    Roger Staubach Jersey
    Roy L. WilliamsJersey
    Roy Williams Jerseys
    Tashard Choice Jersey
    Terence Newman Jersey
    Terrell Owens Jerseys
    Terry Glenn Jersey
    Tony Dorsett Jersey
    Tony Romo Jerseys
    Troy Aikman Jersey
    Zach Thomas Jersey
    Cowboys Men’s Jersey
    Cowboys ReplicaJersey
    Cowboys PremierJersey
    Cowboys

    AuthenticJerseys
    Cowboys

    PersonalizedJersey
    Cowboys Women’s Jersey
    Cowboys Kids Jersey
    Cowboys Hat

Leave a Reply