MySql5.7 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

在mysql配置文件my.ini的mysqld下面添加一句default_password_lifetime=0重启mysql服务就行了。下面是截取了mysql官方文档关于密码过期策略的介绍。


6.3.6 Password Expiration Policy

MySQL enables database administrators to expire account passwords manually, and to establish a policy for automatic password expiration.

To expire a password manually, the database administrator uses the ALTER USER statement:

ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE;

This operation marks the password expired in the corresponding mysql.user table row.

Automatic password expiration is available in MySQL 5.7.4 and later. The mysql.user table indicates for each account when its password was last changed, and the server automatically treats the password as expired at client connection time if it is past its permitted lifetime. This works with no explicit manual password expiration.

The default_password_lifetime system variable defines the global automatic password expiration policy. It applies to accounts that use MySQL built-in authentication methods (accounts that use an authentication plugin of mysql_native_passwordmysql_old_password, or sha256_password).

The default default_password_lifetime value is 0, which disables automatic password expiration. If the value of default_password_lifetime is a positive integer N, it indicates the permitted password lifetime; passwords must be changed every N days.

Note

From MySQL 5.7.4 to 5.7.10, the default default_password_lifetime value is 360 (passwords must be changed approximately once per year). For those versions, be aware that, if you make no changes to the default_password_lifetime variable or to individual user accounts, all user passwords will expire after 360 days, and all user accounts will start running in restricted mode when this happens. Clients (which are effectively users) connecting to the server will then get an error indicating that the password must be changed: ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

However, this is easy to miss for clients that automatically connect to the server, such as connections made from scripts. To avoid having such clients suddenly stop working due to a password expiring, make sure to change the password expiration settings for those clients, like this:

ALTER USER 'script'@'localhost' PASSWORD EXPIRE NEVER

Alternatively, set the default_password_lifetime variable to 0, thus disabling automatic password expiration for all users.

Examples:

  • To establish a global policy that passwords have a lifetime of approximately six months, start the server with these lines in an option file:

    [mysqld]
    default_password_lifetime=180
    
  • To establish a global policy such that passwords never expire, set default_password_lifetime to 0:

    [mysqld]
    default_password_lifetime=0
    
  • default_password_lifetime can also be changed at runtime (this requires the SUPER privilege):

    SET GLOBAL default_password_lifetime = 180;
    SET GLOBAL default_password_lifetime = 0;
    

No matter the global policy, it can be overridden for individual accounts with ALTER USER:

  • Require the password to be changed every 90 days:

    ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE INTERVAL 90 DAY;
    
  • Disable password expiration:

    ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER;
    
  • Defer to the global expiration policy:

    ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE DEFAULT;
    

These ALTER USER statements update the corresponding mysql.user table row.

When a client successfully connects, the server determines whether the account password is expired:

  • The server checks whether the password has been manually expired and, if so, restricts the session.

  • Otherwise, the server checks whether the password is past its lifetime according to the automatic password expiration policy. If so, the server considers the password expired and restricts the session.

A restricted client operates in sandbox mode,, which limits the operations permitted to the client (see Section 6.3.7, “Password Expiration and Sandbox Mode”). Operations performed by a restricted client result in an error until the user establishes a new account password:

mysql> SELECT 1;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

mysql> ALTER USER USER() IDENTIFIED BY 'new_password';
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

This restricted mode of operation permits SET statements, which is useful before MySQL 5.7.6 if SET PASSWORD must be used instead of ALTER USER and the account password has a hashing format that requires old_passwords to be set to a value different from its default.

It is possible for an administrative user to reset the account password, but any existing sessions for that account remain restricted. A client using the account must disconnect and reconnect before statements can be executed successfully.

Note

It is possible to reset a password by setting it to its current value. As a matter of good policy, it is preferable to choose a different password.

当你在安装MySQL 8.0之后执行相关语句时,如果出现"ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement."的错误,你需要通过ALTER USER语句重置你的密码才能执行该语句。解决这个问题有几种方法可以尝试使用: 方法一: 1. 打开MySQL命令行工具,并输入以下命令: ALTER USER USER() IDENTIFIED BY 'your_password'; 这将重置你的密码为你指定的"your_password"。 方法二: 1. 修改root密码。可以使用以下步骤: a. 打开MySQL命令行工具,并输入以下命令: SET PASSWORD FOR 'root'@'localhost' = PASSWORD('your_password'); 这将修改root用户的密码为你指定的"your_password"。 b. 重新登录MySQL并使用新密码进行验证。 方法三: 1. 使用以下语句修改密码: SET PASSWORD = 'your_password'; 你需要将"your_password"替换为你想要设置的密码。 2. 如果你的密码符合MySQL的要求,那么修改密码会成功。如果出现"ERROR 1819 (HY000): Your password does not satisfy the current policy requirements"的错误信息,则需要执行以下两条语句: SET GLOBAL validate_password.policy=0; SET GLOBAL validate_password.length=1; 然后再次执行步骤1中的语句即可。 希望以上方法能够帮助你解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [【已解决】【Mysql8.0】ERROR 1820 (HY000): You must reset your password using ALTER USER statement](https://blog.csdn.net/wingrez/article/details/99825144)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [分享MySql8.0.19 安装采坑记录](https://download.csdn.net/download/weixin_38703794/13683419)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值