user_admin can create users, alter users, and drop users in the database.
After a cluster is created, the system automatically generates a root user with root privileges. Because the root user and role have all privileges of the system, we recommend that you create new users and roles for subsequent operations to prevent any risky operations. Keep the password of the root user properly.
Create user
You can create a user by specifying the user identity, the authentication method, and optionally the default role. To enable the native authentication for the user, you need to explicitly specify the password in plaintext or ciphertext. The following example creates the userjack, allows it to connect only from the IP address 172.10.1.10, enables the native authentication, sets the password to 12345 in plaintext, and assigns the role example_role to it as its default role:
- The database encrypts users’ passwords before storing them. You can get the encrypted password using the password() function.
- A system-defined default role
PUBLICis assigned to a user if no default role is specified during user creation.
Alter user
You can alter the password, default role, or property for a user. For instructions on how to alter the default role for a user, see Alter default role.Alter the property of a user
You can set the property of a user using ALTER USER. The following example sets the maximum number of connections for userjack to 1000. User identities that have the same user name share the same property.
Therefore, you only need to set the property for jack and this setting takes effect for all the user identities with the user name jack.
Reset password for a user
You can reset the password for a user using SET PASSWORD or ALTER USER.NOTEBoth the following examples reset the password of
- Any user can reset their own passwords without needing any privileges.
jack to 54321:
-
Reset the password using SET PASSWORD:
-
Reset the password using ALTER USER:
Reset lost root password
Only theroot user itself can set its password. If you have lost the password of the root user and cannot connect to the database, you can reset it by following these procedures:
-
Add the following configuration item to the configuration files fe/conf/fe.conf of all FE nodes to disable user authentication:
-
Restart all FE nodes to allow the configuration to take effect.
-
Connect from a MySQL client to the database via the
rootuser. You do not need to specify the password when user authentication is disabled. -
Reset the password for the
rootuser. -
Re-enable user authentication by setting the configuration item
enable_auth_checktotruein the configuration files fe/conf/fe.conf of all FE nodes. -
Restart all FE nodes to allow the configuration to take effect.
-
Connect from a MySQL client to the database using the
rootuser and the new password to verify whether the password is reset successfully.
Drop a user
You can drop a user using DROP USER. The following example drops the userjack:
View users
You can view all the users within the cluster using SHOW USERS.View user property
You can view the property of a user using SHOW PROPERTY. The following example shows the property of the userjack: