RENAME USER

RENAME USER 语句用于对已有用户进行重命名。

语法图

  1. RenameUserStmt ::=
  2. 'RENAME' 'USER' UserToUser ( ',' UserToUser )*
  3. UserToUser ::=
  4. Username 'TO' Username
  5. Username ::=
  6. StringName ('@' StringName | singleAtIdentifier)? | 'CURRENT_USER' OptionalBraces

示例

  1. CREATE USER 'newuser' IDENTIFIED BY 'mypassword';
  1. Query OK, 1 row affected (0.02 sec)
  1. SHOW GRANTS FOR 'newuser';
  1. +-------------------------------------+
  2. | Grants for newuser@% |
  3. +-------------------------------------+
  4. | GRANT USAGE ON *.* TO 'newuser'@'%' |
  5. +-------------------------------------+
  6. 1 row in set (0.00 sec)
  1. RENAME USER 'newuser' TO 'testuser';
  1. Query OK, 0 rows affected (0.08 sec)
  1. SHOW GRANTS FOR 'testuser';
  1. +--------------------------------------+
  2. | Grants for testuser@% |
  3. +--------------------------------------+
  4. | GRANT USAGE ON *.* TO 'testuser'@'%' |
  5. +--------------------------------------+
  6. 1 row in set (0.00 sec)
  1. SHOW GRANTS FOR 'newuser';
  1. ERROR 1141 (42000): There is no such grant defined for user 'newuser' on host '%'

MySQL 兼容性

RENAME USER 语句与 MySQL 完全兼容。如发现任何兼容性差异,请在 GitHub 上提交 issue

另请参阅