3

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.

5
  • 1
    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.
    – Dave Rix
    Jun 2, 2015 at 10:21
  • Setup test2.activity as a view to test.activity with condition? Jun 3, 2015 at 2:03
  • @TanHongTat and then ??\ Jun 4, 2015 at 4:19
  • I assume you need the replication to keep the data in sync, so, instead of setting up a replication, you can simply setup a view to the original table. Jun 4, 2015 at 4:29
  • but i want replication in another database. Jun 4, 2015 at 4:33

5 Answers 5

0

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.

2
  • isnt it possible in same way as we have in SQL-SERVER for distributor/publisher Jun 2, 2015 at 10:52
  • Not that I'm aware of.
    – Dave Rix
    Jun 2, 2015 at 12:13
1

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 .

4
  • i have only one mysql 5.6 instance on my system Jun 2, 2015 at 10:39
  • Ok. you can install another one with different configuration file that will be up another MySQL instance on separate port number and other attributes. Unless I do not know another approach.
    – nima0102
    Jun 3, 2015 at 11:17
  • nima0102 - i have to check for the another installation. Jun 4, 2015 at 4:20
  • Yes. You can have 2 or more MySQL instance with different configuration. Of course, if your intention is just only for experimental, I do suggest visualization software to do your tests. Installation easily separate OS and then deploy MySQL.
    – nima0102
    Jun 4, 2015 at 11:44
0

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.

1
  • Trigger is not my solution Jun 4, 2015 at 4:20
0

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.