Question

I have set the Master DB Name as MDB & in the Slave server I set to replicate-do-db=SDB <-- this did not work? But when I set it up as the same DB name it works. Is there any solution out there to setup 1 master db with 2 different slaves but in the same server??

Was it helpful?

Solution

You need to specify the replicate-rewrite-db option:

--replicate-rewrite-db=from_name->to_name

Tells the slave to translate the default database (that is, the one selected by USE) to to_name if it was from_name on the master. Only statements involving tables are affected (not statements such as CREATE DATABASE, DROP DATABASE, and ALTER DATABASE), and only if from_name is the default database on the master. This does not work for cross-database updates. To specify multiple rewrites, use this option multiple times. The server uses the first one with a from_name value that matches. The database name translation is done before the --replicate-* rules are tested.

If you are only replicating certain databases, you will need to specify the replicate-do-db. Note that the argument to this is the name of the database after the rename operation applied by replicate-rewrite-db:

--replicate-do-db=db_name

OTHER TIPS

MySQL Replication with different database names

Add the following to the logging and replication section of your MySQL configuration file (/etc/mysql/my.cnf), I inserted mine right above relay-log.

replicate-rewrite-db = db_1->db_2

Replace db_1 with the database's name being replicated from the remote master and db_2 with the destination database's name.

  • Restart the MySQL server (/etc/init.d/mysql restart)
  • Access the MySQL shell (mysql -h localhost -u root -p)
  • Check the Slave status (SHOW SLAVE STATUS\G)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top