Solved

Php script to copy MySql database from one server to another via a remote connection

Posted on 2014-01-13
5
968 Views
Last Modified: 2014-04-10
Is there a free Php script available that will copy a MySql database from a remote server to a host server via a remote connection? I can't do this using mysqldump because I don't have SSH access on the remote server. At the moment I'm having to download the Db via PhpMyadmin and upload on the new server via PhpMyadmin.
0
Comment
Question by:ncw
  • 2
  • 2
5 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39776425
How often do you want to do this?
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 39776710
If you have remote MySQL access on your remote server and SSH access on the new server, then you can simply run mysqldump from the new server and give it credentials to the old/remote server.

If you just need to do this on occasion with small databases, then I recommend you use HeidiSQL. It's a free MySQL GUI tool for Windows, and it has a feature that allows you to copy databases between servers (although the tool itself is labeled as "Export database to SQL" and you have to choose the new database as the destination in the popup). It's far superior to phpMyAdmin, in my opinion.
0
 
LVL 1

Author Comment

by:ncw
ID: 39838704
As the title suggests, I'm looking for a Php script.

> How often do you want to do this?
May be once a month.
0
 
LVL 1

Author Comment

by:ncw
ID: 39981475
I've requested that this question be deleted for the following reason:

No solution found.
0
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 39981476
Sorry, it's been a busy few weeks and I didn't see your response. My apologies for the late reply.

Ultimately, it's just a really bad idea to use PHP to try and dump and copy a database. It's like trying to use a guy on horseback to transport the contents of a bank vault from one side of a country to the other. It's prone to failure and loss and lacks ALL of the advantages provided by the tool that the MySQL developers themselves built to do this very thing.

If you're desperate for a PHP approach, I wrote a PHP library for doing this type of stuff a LONG LONG time ago. You can still find it around in places like this:

http://www.codewalkers.com/c/a/Database-Code/dbUtils/

...but it's WAY out of date, doesn't lock tables, uses deprecated extensions, etc... Trust me, if I thought it was a good idea to do it this way today, I would have just updated the library (it can still be used as-is). If you're insistent on this approach, there may be a class on phpclasses.org that gives you some of this approach and uses some updated methods.

Also, you said you wanted a PHP script because you didn't have remote SSH access, but as I mentioned, you don't need SSH access on the remote server to run mysqldump on that remote server. You only need access on ONE server in order to run mysqldump, because you can run mysqldump against a remote host.

In fact, you could even run a scheduled job from ANY computer that has the mysqldump and mysql binaries (even a Windows PC with a scheduled task), although the more computers involved, the less secure it all is.

I'd recommend using sudo to run a PHP script to execute mysqldump or set up a cron job to run mysqldump directly before I would ever recommend using a PHP script to manually copy databases over.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question