Solved

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

Posted on 2014-01-13
5
1,031 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 110

Expert Comment

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

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 35

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 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