add mysql2 bindings, move common code to separate file