Sunday, January 16, 2011

500 Internal Server when importing database via PHP

I get a 500 Internal Server Error in my web browser immediately after I view a php page that runs the following script:

exec("mysql -h db.server.com -u myuser -pmypass db < db.sql");

The mysql command takes a long time to execute because db.sql is a very big file and it takes time to send it to an external database server. While the command executes, all other php pages on my shared hosting services yields a 500 Internal Server error.

Is there a way to get rid of the 500 internal server error and have my other php pages running? Is there a better way to import my sql file?

  • Can you run the command from a shell instead of a webpage?

    John : I don't think I because this is for a non-technical user who wants to export his Ms Access Db, then upload through a PHP webform where it automatically imports to mysql. His MS Access Db is not normalized and full of junk, maybe I should ask him to clean up the database so it's a smaller file.
    mrdenny : If the data can be cleaned up and data removed from the output file that's probably the easiest solution without importing the file from the command line.
    From mrdenny
  • Have the php program save the SQL file to a temporary location on the remote machine and have a cronjob that runs and looks for files in that location and sucks them up into MySQL.

    Also set up the php script to create a file in the same directory when the file is beginning to be uploaded so you can write your cronjob to ignore to not attempt to read it while its being uploaded.

    From Josh Budde

0 comments:

Post a Comment