ALTER USER

Description

Modify the attributes and passwords of database users.

Note

  1. Accounts can modify the passwords of the users they create and only modify the passwords of one user at a time. The modified passwords will take effect on the next login, and the current session will not be interrupted.
  2. Users can modify their own passwords, and the modified passwords will take effect on the next login, and the current session will not be interrupted.

Syntax

  1. ALTER USER [IF EXISTS]
  2. user auth_option
  3. auth_option: {
  4. IDENTIFIED BY 'auth_string'}

Explanations

auth_option

Specifies the default user name and authorization mode of the account, auth_string specifies the password explicitly.

Examples

  1. -- Create a user named "admin_1" with password "123456"
  2. mysql> create user admin_1 identified by '123456';
  3. Query OK, 0 rows affected (0.02 sec)
  4. -- Modify the user's initial password "123456" to "111111"
  5. mysql> alter user 'admin_1' identified by '111111';
  6. Query OK, 0 rows affected (0.02 sec)
  7. -- Check if the password was changed successfully
  8. mysql> select * from mo_catalog.mo_user;
  9. +---------+-----------+-----------+-----------------------+--------+---------------------+--------------+------------+---------+-------+--------------+
  10. | user_id | user_host | user_name | authentication_string | status | created_time | expired_time | login_type | creator | owner | default_role |
  11. +---------+-----------+-----------+-----------------------+--------+---------------------+--------------+------------+---------+-------+--------------+
  12. | 0 | localhost | root | 111 | unlock | 2023-04-19 06:37:58 | NULL | PASSWORD | 0 | 0 | 0 |
  13. | 1 | localhost | dump | 111 | unlock | 2023-04-19 06:37:58 | NULL | PASSWORD | 0 | 0 | 0 |
  14. | 2 | localhost | admin_1 | 111111 | unlock | 2023-04-21 06:21:31 | NULL | PASSWORD | 1 | 0 | 1 |
  15. +---------+-----------+-----------+-----------------------+--------+---------------------+--------------+------------+---------+-------+--------------+
  16. 3 rows in set (0.01 sec)