HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

SET PASSWORD

Function

Change the user password.

Precautions

  • If no user is specified, the password of the current user is changed.
  • An initial user can change the password of any user (including its own password). REPLACE does not need to be specified to verify the current password.
  • A non-initial user cannot change the password of an initial user.
  • The sysadmin user and users with the createrole permission can change the passwords of other users (non-initialization, non-sysadmin, and non-createrole users). REPLACE does not need to be specified to verify the current password.
  • When the sysadmin user or a user with the createrole permission changes the password, REPLACE must be specified to verify the current password.

Syntax

SET PASSWORD [FOR user] = password_option [REPLACE 'current_auth_string']

password_option: {
    'auth_string'
  | PASSWORD('auth_string')
}

Parameter Description

  • [FOR user]

    user supports the following formats:

    1. user (case insensitive).
    2. 'user' (case sensitive).
    3. “user” (case sensitive)
    4. 'user'@'host' (case sensitive).
    5. current_user()/current_user.
  • auth_string

    Password to be set.

  • current_auth_string

    Old password.

Examples

--Changes the password of the specified user.
MogDB=# create user user1 with password 'abcd@123';
CREATE ROLE
MogDB=# set password for user1 = 'abcd@124';
ALTER ROLE

--Changes the password of the current user.
MogDB=# set password = 'abcd@123';
ALTER ROLE
MogDB=# set password for current_user = 'abcd@123';
ALTER ROLE
MogDB=# set password for current_user() = 'abcd@123';
ALTER ROLE
Copyright © 2011-2024 www.enmotech.com All rights reserved.