loading huge sql files into godaddy
the problem
for the past year or so, we have been suggesting that all of our clients use godaddy for web hosting. for as long as we have been suggesting them, we have not had any problems with them.
the one beef i have always had with them is that it is a huge pain to load up a mysql database from a sql file. for pretty much all of our sites, we use typo3 as our content managment system. this system produces a fairly large sql file. one of the tables in that file (a caching table) is way over 2mb. this means that we can’t split it up to upload it to phpmyadmin. the other problem is that while the control panel says that it supports zip, i can’t, for the life of me, get it to work.
the almost solution
in the past, what i have done is upload the sql file to a remote directory, then get on the phone with godaddy tech support and BEG them to load up the file. this is a really big pain for everyone involved, as there is alot of naming schemes and questions that everyone has to agree on before anything can happen. they are extremely cautious when doing this (as well they should be), so this can take an incredible amount of time to plow through.
after about a day or so, i finally end up with something workable, and we can move on.
the final solution
after going through this many times, i remembered a command in php: “system();“.
this command allows you to feed a string into the command line, and have it evaluated. you are then returned whatever the response to the command is..
so, all you have to do is make a php file with something like this in it:
[sourcecode language=’php’]
php echo ''; //in this line, the DBNAME is the name of the database you are populating //the databse.sql is the file you uploaded .. change those names to something //that makes sense $command = "mysql DBNAME < datbase.sql" $last_line = system($command, $retval); // Printing additional info echo '
Last line of the output: ‘ . $last_line . ‘
Return value: ‘ . $retval; ?>
[/sourcecode]
so, here’s how you do it:
- upload your sql file to a unique directory. make it a temp directory, so you can just delete the whole thing when you’re done.
- upload the file with the php code above to the same directory.
- using your web navigator, go to the php page you created. this will automatically run your code.
- take note of anything weird that shows up in the output, but chances are, everything will go just fine.
- delete the entire directory, to make sure no one accidentally overwrites anything.
some notes
in most cases, when running mysql from the command line, you have to add “-u username -p password” to authenticate you as a user. with godaddy’s hosting, simply running “mysql” logs you in with the correct credentials. if you try to specify credentials manually, it will flop.
hope that was helpful to someone out there!
i spent 12 hours programming with scott yesterday. although i always thought i was a pretty good and pretty thoughtful programmer, i have never met anyone who was as a good a programmer as scott. without getting too wrapped up in the details, i think what i gleaned most from working with scott was that i have been trying to throw alot of heavyweight at alot of lightweight problems. i have spent way too much time trying to figure out how to make the tools i have fit the problem at hand.
working with scott, he had the opposite approach. fit the problem at hand to the tools.
i seem to do this alot, since i can remember. i spend too much time trying to come up with a sophisticated or elegant solution to a problem. in the meantime, the problem gets lost in the mud of the solution.
i thought it was cool that while scott acknowledges that he is one of the heaviest heavyweight programmers, this is due to the fact that this is ALL he’s done his whole life. i found him a good teacher.. and a good listener.. and a good dude..