Skip to main content
ALTER USER modifies user information, including password, authentication method, default roles, and user properties (supported from v3.3.3 onwards). Tip Common users can use this command to modify information for themselves. Only users with the user_admin role can modify information for other users.

Syntax

Parameters

  • user_identity consists of two parts, “user_name” and “host”, in the format of username@'userhost'. For the “host” part, you can use % for fuzzy match. If “host” is not specified, ”%” is used by default, meaning that the user can connect to the database from any host. However, when you use this statement with SET PROPERTIES to modify the user properties, you must specify the username instead of user_identity.
  • auth_option specifies the authentication method. Currently, three authentication methods are supported: the database native password, mysql_native_password, and “authentication_ldap_simple”. The database native password is the same as mysql_native_password in logic but slightly differs in syntax. One user identity can use only one authentication method. You can use ALTER USER to modify users’ passwords and authentication methods.
Note: the database encrypts users’ passwords before storing them.
  • DEFAULT ROLE sets the default role for the user.
    Before you run ALTER USER to set default roles, make sure that all the roles have been assigned to users. The roles are automatically activated after the user logs in again.
  • SET PROPERTIES sets user properties, including the maximum user connection number (max_user_connections), password policy, catalog, database, or session variables on the user level. User-level session variables take effect as the user logs in. This feature is supported from v3.3.3.
    Tip
    • SET PROPERTIES works on user instead of user identity. Therefore, when modifying the user properties, you must specify the username instead of user_identity in the ALTER USER statement.
    • Global variables and read-only variables cannot be set for a specific user.
    • Variables take effect in the following order: SET_VAR > Session > User property > Global.
    • PASSWORD_POLICY can be set only by ALTER USER ... SET PROPERTIES. It is not supported in CREATE USER.
    • If a user does not have PASSWORD_POLICY configured, the system-level password policy is used. If PASSWORD_POLICY is configured for the user, it overrides the system-level password policy for password validation, password expiration, and password retry lockout.
    • A password policy that is still bound to users cannot be dropped.
    • You can use SHOW PROPERTY to view the properties of a specific user.

Examples

Example 1: Change user’s password to a plaintext password.
Example 2: Change user’s password to a ciphertext password.
You can get the encrypted password using the password() function.
Example 3: Change the authentication method to LDAP.
Example 4: Change the authentication method to LDAP and specify the distinguished name (DN) of the user in LDAP.
Example 5: Change the default roles of the user to db_admin and user_admin. Note that the user must have been assigned these two roles.
Example 6: Set all roles of the user, including roles that will be assigned to this user as default roles.
Example 7: Clear all the default roles of the user.
Note: By default, the public role is still activated for the user.
Example 8: Set the maximum user connection number to 600.
Example 9: Set the catalog of the user to hive_catalog.
Example 10: Set the database of the user to test_db in the default catalog.
Example 11: Set the session variable query_timeout to 600 for the user.
Example 12: Clear the properties set for the user.
Example 13: Bind the password policy pwd_policy_1 to the user.
Example 14: Unbind the password policy from the user and fall back to the system-level password policy.

References