Changed order of MySQL SET CHARACTER queries

Fixes #1826 
This solution is preventing fatal errors for newer MySQL servers, see issue notes.