Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql database Multi-master replication on dynamic ip

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 :).

like image 765
Zalaboza Avatar asked Oct 03 '22 03:10

Zalaboza


2 Answers

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

like image 151
DaImTo Avatar answered Oct 10 '22 22:10

DaImTo


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!

like image 21
Chris Roy Avatar answered Oct 10 '22 22:10

Chris Roy