def user_chpass(user, host='localhost', password=None, password_hash=None, allow_passwordless=False, unix_socket=None, password_column=None, **connection_args):
 args = {}
 if (password is not None):
  password_sql = 'PASSWORD(%(password)s)'
  args['password'] = password
 elif (password_hash is not None):
  password_sql = '%(password)s'
  args['password'] = password_hash
 elif (not salt.utils.is_true(allow_passwordless)):
  log.error('password or password_hash must be specified, unless allow_passwordless=True')
  return False
 else:
  password_sql = "''"
 dbc = _connect(**connection_args)
 if (dbc is None):
  return False
 if (not password_column):
  password_column = __password_column(**connection_args)
 cur = dbc.cursor()
 qry = (((('UPDATE mysql.user SET ' + password_column) + '=') + password_sql) + ' WHERE User=%(user)s AND Host = %(host)s;')
 args['user'] = user
 args['host'] = host
 if (salt.utils.is_true(allow_passwordless) and salt.utils.is_true(unix_socket)):
  if (host == 'localhost'):
   qry += ' IDENTIFIED VIA unix_socket'
  else:
   log.error('Auth via unix_socket can be set only for host=localhost')
 try:
  result = _execute(cur, qry, args)
 except MySQLdb.OperationalError as exc:
  err = 'MySQL Error {0}: {1}'.format(*exc)
  __context__['mysql.error'] = err
  log.error(err)
  return False
 if result:
  _execute(cur, 'FLUSH PRIVILEGES;')
  log.info("Password for user '{0}'@'{1}' has been {2}".format(user, host, ('changed' if any((password, password_hash)) else 'cleared')))
  return True
 log.info("Password for user '{0}'@'{1}' was not {2}".format(user, host, ('changed' if any((password, password_hash)) else 'cleared')))
 return False

def user_chpass ( user , host = 'localhost' , password = None , password_hash = None , allow_passwordless = False , unix_socket = None , password_column = None , ** connection_args ) : args = { } if ( password is not None ) : password_sql = 'PASSWORD(%(password)s)' args [ 'password' ] = password elif ( password_hash is not None ) : password_sql = '%(password)s' args [ 'password' ] = password_hash elif ( not salt . utils . is_true ( allow_passwordless ) ) : log . error ( 'password or password_hash must be specified, unless allow_passwordless=True' ) return False else : password_sql = "''" dbc = _connect ( ** connection_args ) if ( dbc is None ) : return False if ( not password_column ) : password_column = __password_column ( ** connection_args ) cur = dbc . cursor ( ) qry = ( ( ( ( 'UPDATE mysql.user SET ' + password_column ) + '=' ) + password_sql ) + ' WHERE User=%(user)s AND Host = %(host)s;' ) args [ 'user' ] = user args [ 'host' ] = host if ( salt . utils . is_true ( allow_passwordless ) and salt . utils . is_true ( unix_socket ) ) : if ( host == 'localhost' ) : qry += ' IDENTIFIED VIA unix_socket' else : log . error ( 'Auth via unix_socket can be set only for host=localhost' ) try : result = _execute ( cur , qry , args ) except MySQLdb . OperationalError as exc : err = 'MySQL Error {0}: {1}' . format ( * exc ) __context__ [ 'mysql.error' ] = err log . error ( err ) return False if result : _execute ( cur , 'FLUSH PRIVILEGES;' ) log . info ( "Password for user '{0}'@'{1}' has been {2}" . format ( user , host , ( 'changed' if any ( ( password , password_hash ) ) else 'cleared' ) ) ) return True log . info ( "Password for user '{0}'@'{1}' was not {2}" . format ( user , host , ( 'changed' if any ( ( password , password_hash ) ) else 'cleared' ) ) ) return False
change password for a cluster admin or a database user .