Question

What I have :

  • a windows machine with one instance of MySQL 5.6 Server.
  • two database named test and test2.
  • Test database has a table called activity with columns id and class

What I need :

  • replication of test.activity table to test2 database with a condition that Test.activity.class = 'B'.

I know how to replicate with in different server. But not for same server within different database.I have checked this link , but it does not give enough information.

Was it helpful?

Solution

That wouldn't be a normal situation at all! You can't alter the database during replication, and the master / slave cannot have the same server ids. I'd recommend if you must do this, then set up some triggers on the first DB, to replicate the insert / update commands against the second one.

OTHER TIPS

Cause it's on the same server, why don't you use a trigger for this?

If you just wanna replicate data you can add a triger on update or on insert or both whatever you need. This way you can use your condition easily. Master/Slave replication would be better for different servers.

You can look here for mysql Trigger examples. And here is a sample for your case.

If i did understand correctly your need, You can have 2 MySQL instances on one single server (OS) then you could configure one of them as Master and another as Slave. You must create different my.conf,we named it my1.conf and my2.conf that each one should be different on port number and socket path and log error path and some other parameters. With this approach, you will run 2 MySQL daemon with different configurations. For complete doc please go to https://dev.mysql.com/doc/refman/5.1/en/multiple-servers.html .

Try mysql sandbox, it will probably solve your issue (http://mysqlsandbox.net/)

Because:

replication of test.activity table to test2 database with a condition that Test.activity.class = 'B'.

Native replication not help, and in this case better to leave both database on same server and just install trigger for INSER/UPDATE/DELETE on Master database, which will check conditions and make direct changes on second database.

This is simplest way. There are many other possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top