Forums

MySQL Master/Slave Replication

Could someone guide me on how to set up master/slave configuration on pythonanywhere using MySQL databases and Django 1.7.

I'm using the slave as a replica only for now, It's just an alternate form of backup as my website does not need a master/slave setup for issues related to scaling.

Hi, I'm afraid we don't support master/slave setups on our mysql service.

For backups, we're usually seeing people setting up a mysqldump on a Scheduled Task, and optionally uploading the dump to external storage, if they want the reassurance about off-site backups...

Hey, That's a set back , I was getting a lot of Access Denied errors on mysql console. However i figured out a badly designed hack-around, in Django specifying database to use, I could override the save method of a model to save in both the main and backup databases. That ensures replication though it makes the website slower, that's okay for my current setup. Ex.

 def save(self, *args, **kwargs):
    # check if the using parameter is not specified in args or kwargs
    to_ret = super(SomeModelName, self).save(using='default', *args, **kwargs)
    try:
        super(SomeModelName, self).save(using='backup', *args, **kwargs)
    except:
        # Handle race condition while inserting multiple new objects at the same time, maybe force insert or get a lock on the              
        #  backup while inserting into the main one?
        pass
return to_ret

However i can only override the save methods for the models in the django app's that I have written not the third party apps, hence can't assure backup for all models, can you guys help me out over here?

Hey, that's a really ingenious hack, but I really don't think it's going to be a reliable way of doing backups. Like I say, a scheduled task with a "mysqldump" is probably the way to go...