Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 -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?

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer

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

share|improve this answer
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. – John Sep 22 '09 at 1:12
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. – mrdenny Sep 22 '09 at 2:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.