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.

simplifiedDB
  • 649
  • 6
  • 17
  • 35
  • 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 02 '15 at 10:21
  • Setup `test2.activity` as a view to `test.activity` with condition? – Tan Hong Tat Jun 03 '15 at 02:03
  • @TanHongTat and then ??\ – simplifiedDB Jun 04 '15 at 04: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. – Tan Hong Tat Jun 04 '15 at 04:29
  • but i want replication in another database. – simplifiedDB Jun 04 '15 at 04:33

5 Answers5

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 .

nima0102
  • 31
  • 3
  • i have only one mysql 5.6 instance on my system – simplifiedDB Jun 02 '15 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 03 '15 at 11:17
  • nima0102 - i have to check for the another installation. – simplifiedDB Jun 04 '15 at 04: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 04 '15 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.

mim.
  • 111
  • 4
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.

Dave Rix
  • 1,313
  • 9
  • 16
0

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

greenlitmysql
  • 414
  • 2
  • 3
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.

a_vlad
  • 3,462
  • 2
  • 10
  • 16