Major refactor of database functions

Now we only execute inside a virtualenv, we can ensure we have the MySQL
python libraries available.  Which means we can use them rather than
having to go through the command line interface (apart from mysql dump
and restore).

Somewhat untested right now ...