refactor mysql