?
Solved

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

Posted on 2014-01-13
5
Medium Priority
?
1,085 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 111

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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

764 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