Working mysql master fucntion