loading huge sql files into godaddy

Posted by sergio_101 on Feb 1st, 2008
2008
Feb 1

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’]

'; //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!

Leave a Comment




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.