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!






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!
= Good info mate. I needed that ^^
Thanks a lot!!!
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
It is a good article about the mysql database regarding to import a heavier one.
Excellent
By
GeoSathi
http://www.geosathi.com
this is error
ERROR 1231 (42000) at line 4082: Variable ‘sql_mode’ can’t be set to the value of ‘Null’
Thanks, gr8 help for me
=(| I would love to know how to use mysql databases with a form on wordpress to take bookings. Any chance you will branch out and cover this?
I’m not sure what you’re looking for, can you describe it in more detail?
Thank you for taking an interest.
My aim is to have a form on a WordPress blog that takes name, address, mobile, email and 2 dates. I need this information to go onto a mysql database. Even better if the information could be sent in an email too.
Many thanks,
Niamh
just use a contact form. All you need is the cformsII plugin.
“run the following on the command line:
mysqldump -a -u USERNAME -p DATABASE > FILENAME.mysql ”
this may be a really dumb question, but I can’t find any mysql files that end with .mysql (as in your example above). They all end with .myi or .frm. What am I missing? Thanks for your help.
there is no file that ends in .mysql – you are creating one by running the command.
hi,
what should i do if i don’t have access to telnet?
i have only access to FTP, phpmyadmin and cpanel
thank you, john
just use the big dump script linked in the post – you just FTP it to your server and run it from a browser and it does all the work without any need for telnet.
Thanks thanks thanks thanks! After working about 999 hours with phpMyAdmin and the “cancel imports if script time blabla” function (which really doesn’t work well -.-) I’ve found your post and hell – after 10 minutes my database was imported perfectly :-))). Thanks man! =)]
LyricsHawks last blog post..Blood Flower Lyrics from Tilly and the Wall
thanks for sharing
i have problem with my hosting company that can’t allow shell.
so for importing big db i’m using “bigdump”, but i don’t when i have to export it?
any tools like “bigdump” for export big db?
Dewa MP3s last blog post..Download MP3 Dcips – Apa Kabar Gratis
does not work using the 2nd method, says file or directory does not exist when the file is DEFINITELY there and is even chmod at 777. why??
dumpscript does not work too when used on an old webhost nameserver. defeats the purpose since people who does use this would like to test it first before changing nameservers which takes like 2-3 days to propagate.
Appreciate the tips. I needed to reinstall a backup and found you after a Google search.
.-= Forex Currency Trading´s last blog ..is a forex currency trade scam or not? =-.
nice work. I use this to import large product databases in my own mysql.
Hi, my problem is that I only can access to my mysql databases by phpmyadmin in webserver. How do I do it to access by telnet?
I need to export a large db of my leads, but I don’t know how to use telnet. Some help please?
thanks for this valuable information John 🙂
If you’ve never used the command line before your best bet might be to hire someone to do this for you.