Refactor mysql access

Change-Id: If7a35d10703346081f36dc5520dffcf3b28d56e8