Working locally has many advantages. I try to stay away from developing on a production server whenever possible for a number of reasons. The major reason is that I don’t want to make a mistake that can corrupt my data or bring the server down.
I’m currently working on a project that involves calling data from a large database (> 100MB) using some old PHP code a previous developer wrote. I *could* just tinker with it on production but I don’t think that’s a good idea. So I decided to export the database from the production server and then tried bringing it into phpMyAdmin so I could work locally. I kept getting a very ambiguous error saying:
You probably tried to upload too large file. Please refer to documentation for ways to workaround this limit.
Error messages that use the word “probably” kind of irk me, but that’s another post. The documentation was no help either, I tried all the things they recommended but still no luck. I could use a tool they recommended to use in order to split the file up but the disclaimer on the site saying “We are not responsible for lost data” made me not want to use it. It dawned on me that there had to be a way to import this via the command line, and indeed there was. Why didn’t I think of that first.
First create the database you want to import the data to. Either in phpMyAdmin or in the terminal.
To import your abnormally large DB, type this in a terminal:
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot dbname < /path/to/database/you/want/to/import.sql
Obviously if you have a different username, password and database name, change the appropriate parameters. If it is a really large file it may take a while but viola! No more being at the whim of phpMyAdmin, you just took matters into your own hands.