Solved

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

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

Expert Comment

by:Ray Paseur
Comment Utility
How often do you want to do this?
0
 
LVL 34

Expert Comment

by:gr8gonzo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
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 count occurrences of each item in an array.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now