Forums

Best Practice for Moving MySQL Data from Pre-Prod to Production

I have a MySQL database that I first populate locally (little by little) and then I'd like to update on production hosted on pythonanywhere once a week. What is the recommended/best method for keeping these db's in sync? Manual dump from local db and restore on pythonanywhere? Or is there another/better method? I have read that pythonanywhere does not support db replication/synchronizing via script. Since I only do this weekly I don't mind doing a dump/restore procedure but I'd like to be aware of any 'gotchas' beforehand. Thanks!

For what you're trying to do, it sounds like your dump/restore method is probably fine. You could also write some synchronisation code to read the local database and the PythonAnywhere database and then do some sort of reconciliation (that would depend on your database use and structure) and then push the diff up to PythonAnywhere. That would probably be a significant amount of work and take some time to ensure that you have all the corner-cases handled.

Excellent, that "should" be easy enough in principle. However, I tried to import/restore a dump from a single file and MySQL Workbench crashed (repeatedly). Do I need to drop the schema on the pythonanywhere MySQL DB first prior to importing? I wasn't sure if a restore just imported the difference between the file and what was already in the DB or if I, in effect, needed to recreate the entire DB schema and tables along with data from scratch by first wiping, then restoring. Thanks!

The dump of the database includes the entire database including the table creation, so it would be best to restore into an empty database. You might be able to do something like keep the last dump and then only apply the differences when you restore, but that would not handle schema changes and you;d probably get errors if you'd added records to the PythonAnywhere database independently.

Thanks! Last related question: what if our databases grow to larger than the 100MB file upload threshold?

There are a number of ways that you can get large files in and out of PythonAnywhere: https://help.pythonanywhere.com/pages/UploadingAndDownloadingFiles/