Skip to content

Latest commit

 

History

History
114 lines (83 loc) · 4 KB

sql-statement-set-password.md

File metadata and controls

114 lines (83 loc) · 4 KB
title summary aliases
SET PASSWORD
TiDB 数据库中 SET PASSWORD 的使用概况。
/docs-cn/dev/sql-statements/sql-statement-set-password/
/docs-cn/dev/reference/sql/statements/set-password/

SET PASSWORD

SET PASSWORD 语句用于更改 TiDB 系统数据库中的用户密码。

语法图

SetPasswordStmt ::=
    "SET" "PASSWORD" ( "FOR" Username )? "=" ( stringLit | "PASSWORD" "(" stringLit ")" )

示例

{{< copyable "sql" >}}

SET PASSWORD='test';
Query OK, 0 rows affected (0.01 sec)

{{< copyable "sql" >}}

CREATE USER 'newuser' IDENTIFIED BY 'test';
Query OK, 1 row affected (0.00 sec)

{{< copyable "sql" >}}

SHOW CREATE USER 'newuser';
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER for newuser@%                                                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER 'newuser'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

{{< copyable "sql" >}}

SET PASSWORD FOR 'newuser' = 'test';
Query OK, 0 rows affected (0.01 sec)

{{< copyable "sql" >}}

SHOW CREATE USER 'newuser';
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER for newuser@%                                                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER 'newuser'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

{{< copyable "sql" >}}

SET PASSWORD FOR 'newuser' = PASSWORD('test');

上述语法是早期 MySQL 版本的过时语法。

Query OK, 0 rows affected (0.00 sec)

{{< copyable "sql" >}}

SHOW CREATE USER 'newuser';
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER for newuser@%                                                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER 'newuser'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MySQL 兼容性

SET PASSWORD 语句与 MySQL 完全兼容。如发现任何兼容性差异,请尝试 TiDB 支持资源

另请参阅