How to Synchronize mysql databases between local and hosted servers automatically? - php

I would like to synchronize local Mysql db with remote Mysql db.
Due to internet fail, we have to use local application. Once internet problem solved, db should synchronize with remote db.
Because we are using same application in local and remote.

You can use SQLyog which has Database synchronization feature to sync two databases if you are looking for open source tool then refer pt-table-sync http://www.percona.com/doc/percona-toolkit/2.1/pt-table-sync.html

You can make the dump of your local database, and import that on the hosted server when ready.

I think I would create a table changes on a local database and whenever I do any change on the database, it is also saved in the changes table.
For synching then, I'd
loop through changes table and make query-like string
copy it to a clipboard
Have a page on a hosted web with input where to paste that string
When submitted, PHP explodes the string into different queries
Loop through queries and perform them against a hosted database
Of course, here intensive validation should be considered to ensure that the pasted text is a query string copied from the local server

I am afraid you need to do the export and import thing. Don't think there is any automatic kind out there..erm, i would like to know as well

Related

Mysql Database Synchronisation with php codeigniter

I have a PHP codeigniter page which sends data to database every 4 seconds from a device. The page also has options to change the status of the connected device.If there is a problem with the internet connection ,i need to run the page locally and sent the data to local database and later synchronize both the remote and local database so that they are the same.I need a mechanism to synchronize the 2 databases at equal intervals of time.When the site is run live the data go to the remote database.The mechanism should sent the data from remote database to local database also at these intervals.Please share your thoughts.my local server is XAMPP.Remote server is cpanel.
This might help:
have you tried using Replication in MySQL
here:
https://dev.mysql.com/doc/refman/5.0/en/replication.html
You can actually solve your problem but you need to code it and it might be complex and you might also have a problem if you are using an auto increment IDs to solve this try using a custom ID for each record.

How to send data updates to a hosted MySQL database remotely over the internet?

I have a simple MySQL database (one table with 12 rows of data and 5 columns) sitting on the web-server of my host provider.
On my home PC I create the data programmatically and store it in a free version of SQL Server (on my home PC). I would like to "upload" this data to the MySQL db in real time (or as close as I can get) over the internet (I'm assuming this is the only way to connect the pipes).
I know that opening up a MySQL database to a remote internet connection probably is not a "secure" thing to do, but the resulting data table will be publicly available anyway via an "app" so I'm not too worried about that (I suppose a hacker could "overwrite" my data with their own if they were both industrious and inclined) but I think the risk/reward is so small its not a major concern.
Anyway, what is the easiest way to do this with some semblance of security? I only know how to program in VB (I did a little HTML and ASP back in the day, but that was a long time ago). I could learn a few lines of code in another language if need be.
I do not have a static IP, and I've never actually interacted with a MySQL database before (only SQL server, so my MySQL knowledge/ familiarity is zero...but a db is a db, so how hard can it be?). Because of my home network firewall, I can't allow connections "in". I will have to make the connection to the MySQL db "out" from my home PC --> to the hosted database.
Ok this problem is not actually super simple.
What you will find is most shared hosting providers do not allow just any IP to access their databases.
Solution? set the IP for your computer of course! BUT.....you are probably on home internet connection so your IP address can CHANGE (if you have a static IP you are a lucky person!)
So the best way - create a mini-API!
Basically, you want to post your data to a script (with some security of course) that then inserts this data into the database.
It is a lot of work but having done all this before it seems to be the only way unless you have a dedicated server / advanced access privileges!
You could take a look at WAMP for your home pc. It's simple to use.
And then you should take a look at Mysql remote connections(some details here)
I would try this:
At your local computer install MySQL server, there's a free community
edition available for download, try the web installer since its more lightweight. Use the
custom installation and make sure MySql Workbench is selected too.
Workbench has a migration tool for the most common databases, Try this locally, so you can tell if all your data is correctly migrated from your local SQL Server to a MySQL db and there are no data losses in the process.
Then, You could probably connect through Workbench to your online MySQL db
and migrate your data to it directly from your just created local db. In case you cannot connect, make a backup of your local db and send the files to
your server by ftp or similar process. Then, simply restore DB from the backup file on your
online server.
Hope this helps!

Two way mysql database synchronization

I am developing an application whose database needs to be replicated in both directions over multiple number of local offline clients.
Please see the general explanation about it:
User installs client software on personal computer.
User synch data from the remote database server onto local database.
Now User can work on this local database and perform insert, update, delete on it.
At the same time other people can also do insert, update, delete on remote database.
User then connect to remote database and commit their local changes to the remote one.
User retrieve the remote change(Done by other people in remote database) onto their local database.
Right now the idea in my mind is that, We need to track the changes making in remote and local database and creating the web service for replicating the changes, but somewhere I am getting problem with primary keys that might be the same that generated in local and remote database. But this is approach is very lengthy, I also have doubt that it will work on real time or not.
My question is that is there any technology/tool in the MYSQL Server that help me to achieve this task without creating web services. I read out about mysql replication but it work for only one side replication i.e. Master - Slave, I need two sided synchronization.
You may use "Replication concept" between Master and Slave database.
You can read and get some idea about it.
http://learnmysql.blogspot.in/2010/10/setup-and-test-mysql-replication-in-20.html
http://www.percona.com/doc/percona-xtrabackup/2.1/howtos/setting_up_replication.html

Working with mysql when there is no internet connection

I have a php+mysql application and would like to know what's the best way to make my app work when the internet connection is lost.
I thought of having two identical DataBases, one in my internet host, and other in my localhost. So, when there is no connection, I would store all the data to my localhost.
My question is how can I transfer the data from my localhost to the DataBase in my internet host?
You need to use replication - this link will tell you how to set it up so that your local machine is a replica of the remote machine.
Are you just collecting data like subscriptions? If so, you could just queue up new records temporarily when you detect that your main db is down, and do ordinary inserts and deletes to transfer the unprocessed new records when you detect that both databases are available and any unprocessed records exist locally.
If you need to query and maintain relational data between the two databases, then you'll need a more robust and complex replication strategy.
If you have phpMyAdmin on both servers you can export the localhost database and then import it on the hosted database.

Putting data from local SQL database to remote SQL database without remote SQL access enabled (PHP)

I have a local database, and all the tables are defined. Eventually I need to publish my data remotely, which I can do easily with PHPmyadmin. Problem however is that my remote host doesn't allow remote SQL connections at all, so writing a script that does a mysqldump and run it through a client (which would've been ideal) won't help me here. Since the schema won't change, but the data will, I need some kind of PHP client that works "reverse".
Edit: I want this as an automated solution, so I don't have to copy/paste the SQL everytime I make a change!
My question is if such a client exists and what would be recommended to use (by experience). I just need an one way trip here, from my local database (Rails) to the remote database (supports PHP), preferable as simple and slick as possible. Thank you for your replies, comments and feedback!
I believe phpmyadmin has the ability to upload and execute an SQL file, so you can just import a mysqldump via that means.

Categories