MySQL boogaloo and other stuff

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 *)