Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the PASSWORD() function #19364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions functions-and-operators/encryption-and-compression-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ TiDB 支持使用 MySQL 8.0 中提供的大部分[加密和压缩函数](https:/
| [`AES_ENCRYPT()`](#aes_encrypt) | 使用 AES 加密 |
| [`COMPRESS()`](#compress) | 返回压缩后的二进制字符串 |
| [`MD5()`](#md5) | 计算字符串的 MD5 校验和 |
| [`PASSWORD()`](#password) | 计算并返回密码字符串 |
| [`RANDOM_BYTES()`](#random_bytes) | 返回随机字节向量 |
| [`SHA()`](#sha) | 计算 SHA-1 160 位校验和 |
| [`SHA1()`](#sha1) | 计算 SHA-1 160 位校验和 |
Expand Down Expand Up @@ -139,29 +138,6 @@ SELECT MD5('abc');
1 row in set (0.00 sec)
```

### [`PASSWORD()`](https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_password)

> **警告:**
>
> `PASSWORD()` 函数在 MySQL 5.7 中已弃用,在 MySQL 8.0 中已删除,在 TiDB 中也已弃用。不建议使用此函数。

`PASSWORD(str)` 函数计算可用于 `mysql_native_password` 认证方法的密码哈希。

```sql
SELECT PASSWORD('secret');
```

```
+-------------------------------------------+
| PASSWORD('secret') |
+-------------------------------------------+
| *14E65567ABDB5135D0CFD9A70B3032C179A49EE7 |
+-------------------------------------------+
1 row in set, 1 warning (0.00 sec)

Warning (Code 1681): PASSWORD is deprecated and will be removed in a future release.
```

### [`RANDOM_BYTES()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_random-bytes)

`RANDOM_BYTES(n)` 函数返回 `n` 个随机字节。
Expand Down
47 changes: 9 additions & 38 deletions sql-statements/sql-statement-set-password.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ aliases: ['/docs-cn/dev/sql-statements/sql-statement-set-password/','/docs-cn/de

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

> **注意:**
>
> 建议使用 [`ALTER USER`](/sql-statements/sql-statement-alter-user.md) 语句更改密码,如下所示:
>
> ```sql
> ALTER USER myuser IDENTIFIED BY 'mypassword';
> ```

## 语法图

```ebnf+diagram
SetPasswordStmt ::=
"SET" "PASSWORD" ( "FOR" Username )? "=" ( stringLit | "PASSWORD" "(" stringLit ")" )
"SET" "PASSWORD" ( "FOR" Username )? "=" stringLit
```

## 示例

{{< copyable "sql" >}}

```sql
SET PASSWORD='test';
```
Expand All @@ -27,8 +33,6 @@ SET PASSWORD='test';
Query OK, 0 rows affected (0.01 sec)
```

{{< copyable "sql" >}}

```sql
CREATE USER 'newuser' IDENTIFIED BY 'test';
```
Expand All @@ -37,8 +41,6 @@ CREATE USER 'newuser' IDENTIFIED BY 'test';
Query OK, 1 row affected (0.00 sec)
```

{{< copyable "sql" >}}

```sql
SHOW CREATE USER 'newuser';
```
Expand All @@ -52,8 +54,6 @@ SHOW CREATE USER 'newuser';
1 row in set (0.00 sec)
```

{{< copyable "sql" >}}

```sql
SET PASSWORD FOR 'newuser' = 'test';
```
Expand All @@ -62,35 +62,6 @@ SET PASSWORD FOR 'newuser' = 'test';
Query OK, 0 rows affected (0.01 sec)
```

{{< copyable "sql" >}}

```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" >}}

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

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

```
Query OK, 0 rows affected (0.00 sec)
```

{{< copyable "sql" >}}

```sql
SHOW CREATE USER 'newuser';
```
Expand Down
Loading