Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.