Solved

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

Posted on 2014-01-13
5
940 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I want to echo out my field names with its values into a table 10 34
AWS EC2 & RDS Instance 5 35
Checkout Page Input Field not aligned 1 23
Decrypt string by php 7 31
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
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…

773 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