How to run a mysql query when admin updates user role?

You are going in wrong direction there is no way to get user role while admin change from back end. You can retrieve the role object for the current user by calling get_role(), but that’s an object rather than a string with the role name.

function get_user_role($uid) {
global $wpdb;
$role = $wpdb->get_var("SELECT meta_value FROM {$wpdb->usermeta} WHERE meta_key = 'wp_capabilities' AND user_id = {$uid}");
  if(!$role) return 'non-user';
$rarr = unserialize($role);
$roles = is_array($rarr) ? array_keys($rarr) : array('non-user');
return $roles[0];
}