I have two shared hosting accounts, each with a database of its own (its own cPanel login). Assuming these two databases have the same structure, what do I need to do in order to synchronize them?
The synchronization script would be on a domain connected with one of the hosting accounts. I know the MySQL/PHP for synchronizing databases that are on the same account is fairly simple, but what’s confusing me here is how to access the database which is on different hosting?
This isn’t a one-time thing, I need to be able to do this by clicking a button/link.
The only thing that comes to mind is having the remote database export everything to .csv files on a regular basis and have the script on the domain connected to the first database import everything, but there’s gotta be a better way?
In case this whole question is confusing, the gist of the problem is – is there a way to have a script on a domain access a database on a completely different shared hosting account?
In short, no, there’s no way.
Usually, hosting providers allow DB access only to
localhostusers. Meaning that script from another machine can’t access it.Also, what kind of synchronization is it? One-way or two-way? (but, I guess, this is out of scope here)
The only viable solution that comes to mind is some kind of dump/restore procedure.
Example:
webserver
A(source of data) defines an URL, by requesting which you can get dumped content of the DBwebserver
B(destination of data) defines a page with button ‘Sync’.upon clicking the ‘Sync’ button, server
Bwill fetch that URL from serverA, receive A’s data and merge it with its own.NOTE
It is important to secure data export URL. In that script you can check, for example, IP of incoming request, or presence and correctness of “access_token” or whatever you like.