Moving Databases
I recently moved my personal website from GoDaddy to my home server. I have a business connection at my house, and my site gets little enough traffic that hosting at home on my static IP makes sense. Moving the files wasn't really difficult, I FTP'd them down from the old server, and SFTP'd them up to the new server. Moving the database was a bit more challenging, however.
If you have shell access, it's a pretty simple process. On the old server, type:
mysqldump -u username -p databasename > databasebackup.sql
You'll be asked for the password assigned to "username", and then mysqldump will create a file that contains all the information needed to restore your database. One thing to note, however, is that going between different versions of mysql can be problematic. That's where the --compatible flag is handy. You can specify what type of database software you'll be importing to, and mysqldump will (try) to give you a compatible file. Some options are mysql323, postgresql, mysql40, etc. Check the man page for more options and explanations about what they all do.
To restore your database file on the new server, it's just as easy. Simply type:
mysql -u username -p newdatabasename < databasebackup.sql
That should transfer your data simply and easily. If you get errors, you might have to check that --compatible flag, or even do some more work to your database in order to make it compatible. One of the frustrating things with GoDaddy, however, is that you don't get shell access to your hosting account. Since my account was disabled, any mysql tools that might be available via their website were also unavailable. That's why it's important to have some backup software running regularly on your website. I was able to take an automated backup from a week ago, and simply import it into my new server.
The moral of the story, like most, is that backups are VERY important! It's great to know the tools to make a dump of your mysql database, but if something is corrupt, you'll want a backup rather than a fresh dump. If you have any other tips for moving databases from one server to another, feel free to leave them in the comments.
Shawn Powers is an Associate Editor for Linux Journal. You might find him chatting on the IRC channel, or Twitter
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Reply to comment | Linux Journal
36 min 44 sec ago - Reply to comment | Linux Journal
7 hours 30 min ago - Reply to comment | Linux Journal
7 hours 46 min ago - Favorite (and easily brute-forced) pw's
9 hours 38 min ago - Have you tried Boxen? It's a
15 hours 30 min ago - seo services in india
20 hours 1 min ago - For KDE install kio-mtp
20 hours 2 min ago - Evernote is much more...
22 hours 2 min ago - Reply to comment | Linux Journal
1 day 6 hours ago - Dynamic DNS
1 day 7 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
I've just thought that it
I've just thought that it would be a good idea to write a php script that takes advantage of table and row locking.
Best online store
----- http://www.fullstores.com -----
Hi,Dear Ladies and Gentlemen,
1. sport shoes : Jordan ,Nike, adidas, Puma, Gucci, LV, UGG , etc. including women shoes and kids shoes.
2. T-Shirts : BBC T-Shirts, Bape T-Shirts, Armani T-Shirts, Polo T-Shirts,etc.
3. Hoodies : Bape hoody, hoody, AFF hoody, GGG hoody, ED hoody ,etc.
4. Jeans : Levis jeans , Gucci jeans, jeans, Bape jeans , DG jeans ,etc.
----- http://www.fullstores.com -----
----- http://www.fullstores.com -----
Service is our Lift.
enjoy yourself.
thank you!!
::∴★∵**☆.∴★∵**☆.∴★∵**☆.
█████.::∴★∵**☆.∴★∵**☆.
█田█田█::∴★∵**☆.∴★∵**☆.
█田█田█.∴★∵**☆.∴★∵**☆.
█田█田█∴★∵**☆.∴★∵**☆.
█田█田█.★∵**☆.∴★∵**☆.
█████.*******************
◢██□██◣.~~~~~*^_^*
blob fields
If you have blob fields, I would also add the "--hex-blob" option to the mysqldump. I've never had a successful move/restore without it.
Use SQLite
People often overlook the advantages of using SQLite (assuming that you are using PHP5), which has no limitations on database size and handles nearly all standard SQL (except for some DDL operations), but whose data is all contained in a single text file for each database, making it ridiculously simple to migrate and backup. One thing missing in SQLite, though, is password security, so if your application is sensitive, you have to carefully consider how your application can protect your data (locating the file outside the web server document root, etc.).
SQLite performance
SQLite doesn't perform very well under even moderate load, for a smaller site, it may be enough, for a standalone, or workgroup app, sure... but if you are doing a lot of commits/writes on an application with more than a few dozen simultaneous users, it can become a bottleneck, unless you run SQLite on an SSD that is.
A service based RDBMS is really good for having data caching, as well as good performance, I'm pretty fond of FirebirdSQL myself as it can run stand-alone embedded, and migrate to a service based instance. Though it's a bit less popular, it does have some great features. I also like PostgreSQL a lot as well. I'm not much of a fan of mySQL to begin with.
--
Michael J. Ryan - http://tracker1.info/
Watch out for databases with
Watch out for databases with stored procedures/functions in which case you should run mysqldump with the --routines switch. Pain in the backside if you don't do so
moving a hot database
How about writing a script in php that takes advantage of table and row locking?? Just a thought what does everyone else think?
moving the mySQL files
Well, I had to move several databases with users priviledges (not just the root one) from an actual to a new server. The dump wasn't great to me (maybe i am wrong...) because of the mySQL user priviledges definition that i was affraid to lost and to redefine from scrash. So the solution I have found was to copy the data folder of mySQL (with the mdy files) to the mySQL folder of the new server. The result : everything works fine, without to many things to do ! But still a question : since i have seek for MySQL migration on the net, everytime the answer is the mysqldump method, but never the simple files copy method. Is there any inconvenient that I don't know with this ? Or is it just the barbarian (but valuable ?) way to do a mySQL backup ?
There's no garentee it will
There's no garentee it will work across versions or even patches.
Thanks for that precisions.
Thanks for that precisions. Of course, I have forget to tell that I shutdown the services before doing such migration. As I told, everything that I have red is about mysqldump. Even today, I have found a post about "Copy and Backup MySQL Databases with mysqldump".
Check this link :
http://developer.practicalecommerce.com/articles/2978-Copy-and-Backup-My...
It could be very valuable as a complement of this article :-)
Thanks Shawn ! Your posts are really great !
datafile copy ...
a database dump, like oracle expdp utility ,is always consistent itself.
Plain copy of the datafile maybe inconsistent dues to transaction is running and no all the blocks on file system are alligned at the same state of process, so if you start mysql with data corrupted files it can not works properly at data level.
( maybe , it works in most of cases but .. )
Choose always the dump solution, or shutdown mysql server and then copy data file not while it is running or configure a mysql replica or so on.
that's it.
Since he mentions he shuts
Since he mentions he shuts down all services first, I do not see the logic of your post! There should be no more transactions.
:)
his post on Tue, 08/16/2011 - 10:04.
my post on Mon, 08/15/2011 - 19:15.
c ya
:)
I've actually done it that way too, but you have to have intimate control over your servers in order to have the sort of access. Also, the mysql server process needs to be shut down before moving the files. Since you're just plopping the data down, I'm guessing there might be some serious problems with versioning if you don't use similar versions.
But that said, I've done it too, and it worked. The mysqldump stuff is important when you don't have full access to the servers.
Shawn Powers is an Associate Editor for Linux Journal. You might find him chatting on the IRC channel, or Twitter
not only mysql version is the
not only mysql version is the problem but also mysql configurations.
In some worst cases you not able to access datas at all from tables : same version, same datafiles , different configuration.
I tried it on my skin when a colleague tried to tune mysql production database changing some configuration parameters: so no more data was available from some particular tables. Shutdown,reconfigure and startup did work but ... what the hell!
The second question is about server access but if you want to copy datafiles directly you must have necessarily the server access. More, you have to be root on unix/linux machines in most of cases ( in the standard mysql configurations ), so where's the problem about the server control? Mysql on windows machines is a movie that i don't want to see anymore.
Yes, if you don't have server access mysqldump allows you to dump datas remotely,but only if you have IP's/host's permissions ( and certainly you cannot copy datafiles ).
Do that only if you do not have other way to do it because it is not smart to do dues to network load that can be very important on production and large databases: you have to schedule it in low load temporal window to make dump over the net: writing dump on 15k rpm disk can takes dozens of seconds, over the net it can takes hours ...
If you have 10MB database simply don't care and go :)
I understand people like
I understand people like phpMyAdmin, but it gives me the willies. Especially when I get a dozen to a hundred attempts daily from bots to get into my phpMyAdmin files... despite the fact that I don't have PHP nor MySQL installed on this server.
I do look after a wordpress site. I do daily backups of the database with the following:
/usr/bin/mysqldump ${DBSCHEMA} |gzip - --stdout \ >/home/${SITEOWNER}/backups/${DBSCHEMA}.$(date -I).sql.gzEventually I'll figure out something with temp files and zdiff for a form of incremental backups. (I know, I know, real incremental MySQL backups would be if I used binlogging, but those can only be loaded back into MySQL databases, and I'm not confident they can even be reloaded into MySQL databases with different version numbers.)
I'm moved my blog, many...
Hello, I'm using Wordpress. Because it's host at free hosting(s), I usually moving my blog from server to server. I've done this many times. For database backup purpose, export tool in phpMyAdmin is so good. It don't have compatible problems, with me. Beside, backup all blog files is very easy with cPanel, compress them in server, and download this compress file.
Copying the data dir itself
Copying the data dir itself works especially well for me for backups using rsync.