Question

Situation:

Php application with mysql database running on 2 sites

  1. online -static ip X.X.X.X
  2. localhost (not online most of time and dynamic ip)

application traffic is usually low <10 users.

what i need is that whenever a change is done to the online database, this change is pushed to localhost -if its online or when ever its available- and vise versa (any changes done locally is uploaded online to database when ever there is online connection).

is it possible to setup such replication by mysql ? or do i need to write a custom PHP that ping master server and once its available

thanks very much :).

Was it helpful?

Solution 2

Let's first analyze your question:

  1. The problem of accessing MySQL with a dynamic ip. This is very easy. Once you installed MySQL on a server with an ever-changing IP, what you can do is go to NO-IP, DynDNS or any other Dynamic DNS service and register for free with them. Once you've registered with them, you would get a client for your operating system. Install that and then you can access your MySQL server using a domain name.

    Example: Instead of having to access your server at 127.0.0.1, you can access it as mysql-server.easynet.net etc.

  2. Now the second and albeit complex part of your question, how to do available and lazy replication. This is relatively a bit more complex than the previous step. But, what actually happens is that you have to choose a scheme of replication. Basically what you are looking for here is MASTER-MASTER replication since you have a possibility of changes happening at both the MySQL servers. Thus the updates need to be bi-directional, that's what this scheme of replication does. How to do it? Well, I am providing the links which I've found easier to follow:

Master-Master Replication

Step-by-step MySQL Master Replication

I hope that would ease your plight and answer your question! Cheers!

OTHER TIPS

Yes you can do this with replication. Just pick which server you want to be the master and have the second one send all of its changes to the main one then the main one could send its changes back.

Replication can be a bit daunting to set up but once its up and running its grate. http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html

Sure, you can
You need to setup both MySQL servers as Master and Slave at the same time.
Configure the online server as Master, and the localhost server as slave, and once replication is OK.
Configure the localhost as Master and the online server as slave.
I already did that on two servers.

About the dynamic IP on the local host, simply you can use any dynamic IP service like: no-ip, and use the dns name instead of the IP.

Here's a post i've written (in french, but you can get the configuration snippets from it) for setting up a MASTER-MASTER replication with a load balancer (mysql proxy) for balancing SQL queries between both nodes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top