• SET PASSWORD
    • 语法图
    • 示例
    • MySQL 兼容性
    • 另请参阅

    SET PASSWORD

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

    语法图

    SetStmt:

    SetStmt

    示例

    1. mysql> SET PASSWORD='test'; -- change my password
    2. Query OK, 0 rows affected (0.01 sec)
    3. mysql> CREATE USER 'newuser' IDENTIFIED BY 'test';
    4. Query OK, 1 row affected (0.00 sec)
    5. mysql> SHOW CREATE USER newuser;
    6. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    7. | CREATE USER for newuser@% |
    8. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    9. | CREATE USER 'newuser'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK |
    10. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    11. 1 row in set (0.00 sec)
    12. mysql> SET PASSWORD FOR newuser = 'test';
    13. Query OK, 0 rows affected (0.01 sec)
    14. mysql> SHOW CREATE USER newuser;
    15. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    16. | CREATE USER for newuser@% |
    17. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    18. | CREATE USER 'newuser'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK |
    19. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    20. 1 row in set (0.00 sec)
    21. mysql> SET PASSWORD FOR newuser = PASSWORD('test'); -- deprecated syntax from earlier MySQL releases
    22. Query OK, 0 rows affected (0.00 sec)
    23. mysql> SHOW CREATE USER newuser;
    24. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    25. | CREATE USER for newuser@% |
    26. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    27. | CREATE USER 'newuser'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK |
    28. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    29. 1 row in set (0.00 sec)

    MySQL 兼容性

    SET PASSWORD 语句与 MySQL 完全兼容。如有任何兼容性差异,请在 GitHub 上提交 issue。

    另请参阅

    • CREATE USER
    • Privilege Management