Lots of small changes

Fixes the issues I reported earlier today.

Also includes some changes to dbdump_to_csv.sh (my MySQL setup didn't allow writing to any directory and it probably isn't a good idea to create a world-writable directory under web root).