MySQL boogaloo

This commit has been checked for sanity, but does overhaul a fair amount of DB code, so run at your own risk (but it shouldn't DROP DATABASE *)