Free Checking for Bloggers - Sign up in 5 Minutes!
Powered by MaxBlogPress  

 

How to export and import very large mySQL databases | JTPRATT's Blogging Mistakes
JTPratt's Blogging Mistakes





Home » How to export and import very large mySQL databases


 
 
 

Posted in:

blog-setup category image blogging-mistakes category image drupal category image web-hosting category image wordpress category image
7,510 views


I had a very large web site (30,000+ pages) that I wanted to move from one web host to another. Normally I would use phpMyAdmin to export tables or the entire database. This mySQL database was of course too large for that and phpMyAdmin would timeout trying to export, even if I exported only one table at a time (one table had 1.5 million records). It’s very easy to quickly export and import very, very large mySQL databases with even hundreds of thousands of records.

To accomplish this we can’t do it via web page tools or methods. So, we have to use the command line in UNIX. This will require a telnet (preferably secure telnet) account and a basic understanding on simple UNIX commands. You will also enough disk space free to extract your database. If you don’t have telnet access to your web site, you can always submit a support ticket telling them what to do based on these instructions. You will need to know in advance your database name, your database username and password, and whether or not your server is ‘localhost’ or a server name (and what it is). This information is normally already entered in your site’s database config or settings file. If you are using Wordpress it’s in your /wp-config.php file in the root of your site, if you’re using Drupal it’s stored in your /sites/default/settings.php file.

Here are the instructions to export your mySQL database into one file on the UNIX command line:

  • login to your web site using telnet
  • navigate to the directory where you want to store your extracted database file
  • run the following on the command line:
    mysqldump -a -u USERNAME -p DATABASE > FILENAME.mysql
  • check the size of your file (command: ls -al)
  • gzip your file to make the download faster using the command: gzip FILENAME.mysql
  • download your file in ftp to your local pc to upload and import into your new database

Again, if you don’t have telnet access you can probably submit a ticket at your web host and they will extract the file for you so you can download it. Once downloaded you need to upload the file to your new web host so you can import it into a fresh database. First, I want to make you aware of a PHP script called Big Dump that does a ’staggered import’ of mysql files into a new database. Even though it’s staggered (importing in chunks) it has it’s limits. I have successfully used it many times on databases under 50MB. It has also failed miserably for me on a 191MB database. If your database is too big to import using phpMyAdmin but under 50MB - give it a try first. Otherwise you’ll have to import on the command. If you use Big Dump you just enter your mysql server settings into the file itself, and I have had the best results uploading the mysql file to the server (same dir you place bigdump.php in) and hardcode the filename into the file before trying the import.

Now, if your file is >50MB or bigdump.php doesn’t work - I’m going to show you how to do a manual import of your mysql file:

  • upload your mysql file to your new web site
  • create a new blank database using myPHPAdmin
  • note your database username and password, and your mysql servername
  • unzip your database file with this command: gzip -d FILENAME.mysql
  • run the following on the command line to import:
    mysql -u USERNAME -p DATABASE < FILENAME.mysql
  • check your database in myPHPAdmin to make sure all the tables imported properly

That’s it! You’ve now learned how to successfully export and import large mySQL databases when myPHPAdmin or other tools won’t work! Again, if you don’t have telnet access, you can always ask your (new) web host to import the file for you. I did when I migrated from a host I used for 9 years to goDaddy. They don’t offer telnet access, so I uploaded the 191MB mysql file and gave them a call to submit a ticket. In less than 2 hours the import was done and I was very happy!

I’ve had a lot of people ask my why I use goDaddy, and I have to tell you…I have hosted with dozens of companies. I actually setup a small account with goDaddy 6 months ago just to try it out (it was only $3.99 per month). Now, 6 months later I’ve moved everything to them. All of my domain registrations, and all of my sites are completely hosted with goDaddy as of today (that big web site was the last one!). I was paying $29.99 per month for a professional webmaster account. I get the exact same thing (and more) with goDaddy for $14.99 per month. They have deals all the time where I pickup new domains for $1.99, and they had a special just today (when I called about the database import) where in July all web hosting was 25% off. It’s not just 25% off for new customers - it’s 25% off for ALL customers, whether you upgrade or just want to pay ahead. So I paid up a few months in advance to save even more money. That’s my shameless self-promotion for the day - use the host I use: www.GoDaddy.com

*UPDATE*

I almost forgot to add why this was a ‘blogging mistake’!  I was going to migrate all of my web sites to goDaddy last month.  I setup a new account a moved all but 2 or 3 sites - mainly because I couldn’t figure out how to get those huge databases off my old server and into my goDaddy account.  Because I couldn’t figure it out my monthly hosting renewal came up, and I ended up paying for another month.  Since I had a dedicated server (that I was grossly under utilizing), that blogging mistake ended up costing me $214!!  Then I finally did a quick google search for “export large mysql database” and figured it out in an hour.  My mistake was not doing enough research to fix the problem - it’s not like I was tackling something others hadn’t been through (and documented) before.  Google is your friend - always search for solutions to your problems!


7 Responses to “How to export and import very large mySQL databases”

  1. nouffer.info.technology » Blog Archive » How to Import Large MySQL Data Files Has the following to say...

    [...] How to export and import very large mySQL databases [...]

  2. Nada Insyirah » How to Import Large MySQL Data Files Has the following to say...

    [...] How to export and import very large mySQL databases [...]

  3. konijnenhokken Has the following to say...

    thanks a lot for this post, i am using it right now to transfer over my dbases (190mb+) to my new server!

    bookmarked for pleasure! tjanks!

  4. Andrés Mochi Has the following to say...

    = Good info mate. I needed that ^^

    Thanks a lot!!!

  5. fedmich Has the following to say...

    I’m encountering same problems now.. Im importing a 2Million records of lyrics, artis, etc. int a website and the SQL Dump is more than 400MB of dump file. I’m splitting and uploading them at the moment, but Im sure there’s a better way of doing this. Any software (I’ll buy it) there or PHP scripts. THanks in advance

    fedmich’s last blog post..Fedmich Computer Shop on Manila Times closed

  6. GeoSathi Has the following to say...

    It is a good article about the mysql database regarding to import a heavier one.

    Excellent

    By

    GeoSathi
    http://www.geosathi.com

  7. Sniper4Dz Has the following to say...

    this is error

    ERROR 1231 (42000) at line 4082: Variable ’sql_mode’ can’t be set to the value of ‘Null’

Question or Comment?? Spill it Now...

Jumping for Joy over comments!

We Reward Comments!


We dofollow links, and get your latest blog post as a byline under every new comment from the "CommentLuv" plugin! Top commenters for every month are listed on every page of this site in a sidebar widget linked back to your URL! We would like to reward you for becoming part of our community! Your comment is valuable not only to us, but also all the other readers of this blog!
 

 


Click to add smilies to your post! = =[] ^=( =(( =(| =)r =|8 =0 =)~ =00 =( =;; =)] =;;;