php Mysql 密码已过期。无法连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33387879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:28:11  来源:igfitidea点击:

Mysql password expired. Can't connect

phpmysqlmacososx-elcapitan

提问by Coop

I just wiped my Mac and did a fresh install of El Capitan. I'm struggling to connect to Mysql now. Having gone through a web server setup process, I've created a simple PHP test file:

我刚刚擦拭了我的 Mac 并重新安装了 El Capitan。我现在正在努力连接到 Mysql。完成了 Web 服务器设置过程后,我创建了一个简单的 PHP 测试文件:

<?php
  $conn = new mysqli("127.0.0.1", "root", "xxxxxxxx");
  if ($conn->connect_error) echo "Connection failed: " . $conn->connect_error; 
  else echo "Connected successfully";
  phpinfo();
?>

When I run it, I get this error:

当我运行它时,我收到此错误:

Warning: mysqli::mysqli(): (HY000/1862): Your password has expired. To log in you must change it using a client that supports expired passwords. in /Users/rich/Documents/DESIGN/test/index.php on line 3
Connection failed: Your password has expired. To log in you must change it using a client that supports expired passwords.

I've never seen that response from a connection before. How do I fix it if I can't connect?

我以前从未见过来自连接的响应。如果我无法连接,我该如何解决?

EDIT

编辑

In terminal I entered the command:

在终端中,我输入了命令:

mysql -u root -p

mysql -u root -p

This asked me for my password (current one) which I put in. I now have access to mysql commands but anything I try results in this error:

这要求我输入我输入的密码(当前密码)。我现在可以访问 mysql 命令,但是我尝试的任何操作都会导致此错误:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

How do I reset the password using ALTER USER?

如何使用 重置密码ALTER USER

回答by Coop

So I finally found the solution myself.

所以我终于自己找到了解决方案。

Firstly I went into terminal and typed:

首先,我进入终端并输入:

mysql -u root -p

mysql -u root -p

This asked for my current password which I typed in and it gave me access to provide more mysql commands. Anything I tried from here gave this error:

这要求我输入我当前的密码,它让我可以提供更多的 mysql 命令。我从这里尝试过的任何东西都出现了这个错误:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

This is confusing because I couldn't actually see a way of resetting the password using ALTER USERstatement, but I did find another simple solution:

这令人困惑,因为我实际上看不到使用ALTER USER语句重置密码的方法,但我确实找到了另一个简单的解决方案:

SET PASSWORD = PASSWORD('xxxxxxxx');

SET PASSWORD = PASSWORD('xxxxxxxx');

回答by Piotr N.

First, I use:

首先,我使用:

 mysql -u root -p

Giving my current password for the 'root'. Next:

提供我当前的“root”密码。下一个:

mysql> ALTER USER `root`@`localhost` IDENTIFIED BY 'new_password',
       `root`@`localhost` PASSWORD EXPIRE NEVER;

Change 'new_password'to a new password for the user 'root'.
It solved my problem.

更改'new_password'为用户“root”的新密码。
它解决了我的问题。

回答by Kit

mysqladmin -u [username] -p passwordworked for me on OS X El Capitan and MySQL 5.7.12 Community Server. Example:

mysqladmin -u [username] -p password在 OS X El Capitan 和 MySQL 5.7.12 社区服务器上为我工作。例子:

$ /usr/local/mysql/bin/mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

This is similar to pavan sachi's answer, but with password prompts.

这类似于 pavan sachi 的回答,但有密码提示。

My error was "#1862 - Your password has expired. To log in you must change it using a client that supports expired passwords." at phpMyAdmin login screen first time.

我的错误是“#1862 - 您的密码已过期。要登录,您必须使用支持过期密码的客户端更改它。” 第一次在 phpMyAdmin 登录屏幕上。

回答by Dave Everitt

MySQL password expiry

MySQL密码过期

Resetting the password will only solve the problem temporarily. From MySQL 5.7.4 to 5.7.10 (to encourage better security - see MySQL: Password Expiration Policy) the default default_password_lifetimevariable value is 360 (1 year-ish). For those versions, if you make no changes to this variable (or to individual user accounts) allpasswords expire after 360 days.

重置密码只能暂时解决问题。从 MySQL 5.7.4 到 5.7.10(为了鼓励更好的安全性 - 请参阅MySQL:密码过期策略)默认default_password_lifetime变量值为 360(1 年)。对于这些版本,如果您不更改此变量(或个人用户帐户),则所有密码将在 360 天后过期。

So from a script you might get the message: "Your password has expired. To log in you must change it using a client that supports expired passwords."

因此,从脚本中您可能会收到消息:“您的密码已过期。要登录,您必须使用支持过期密码的客户端更改它。”

To stop automatic password expiry, log in as root (mysql -u root -p), then, for clients that automatically connect to the server(e.g. scripts.) change password expiration settings:

要停止密码自动过期,请以 root ( mysql -u root -p)身份登录,然后,为自动连接到服务器的客户端(例如脚本)更改密码过期设置:

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

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

ORyou can disable automatic password expiration for all users:

或者您可以为所有用户禁用自动密码过期:

SET GLOBAL default_password_lifetime = 0;

SET GLOBAL default_password_lifetime = 0;

As pointed out by Mertaydin in the comments, to make this permanent add the following line to a my.cnffile MySQL reads on startup, under the [mysqld]group of settings. The location of my.cnfdepends on your setup (e.g. Windows, or Homebrew on OS X, or an installer), and whether you want this per-user on Unix or global:

正如 Mertaydin 在评论中指出的那样,要使此永久生效,请将以下行添加到my.cnfMySQL 在启动时读取的文件中[mysqld]的设置组下。的位置my.cnf取决于您的设置(例如 Windows,或 OS X 上的 Homebrew,或安装程序),以及您是否想要 Unix 上的每个用户或全局:

[mysqld] default_password_lifetime = 0(There may be other settings here too...)

[mysqld] default_password_lifetime = 0(这里可能还有其他设置...)

See the MySQL docs on configuration files.

请参阅有关配置文件MySQL 文档

回答by pavan sachi

I went through the same issue recently while installing mysql on mac os x capitan. I did not find the correct answer here, so adding this answer.

我最近在 mac os x capan 上安装 mysql 时遇到了同样的问题。我在这里没有找到正确答案,所以添加了这个答案。

MySql in current versions, generates a temporary password when you install mysql. Use this password to set a new password using the mysqladmin utility as below;

当前版本中的 MySql,在安装 mysql 时会生成一个临时密码。使用此密码使用 mysqladmin 实用程序设置新密码,如下所示;

/usr/local/mysql/bin/mysqladmin -u root -p'<your temp password>' password '<your new password>'

/usr/local/mysql/bin/mysqladmin -u root -p'<您的临时密码>' password '<您的新密码>'

Hope it helps you and others.

希望它可以帮助您和其他人。

回答by Grassright

Just download MySQL workbench to log in. It will prompt you to change the password immediately and automatically.

只需下载 MySQL Workbench 即可登录。它会立即自动提示您更改密码。

回答by Mehmet MERCAN

i have faced this issue few days ago. For best solution for 5.7 version of MySQL; login your mysql console and alter your password with the following command:

几天前我遇到了这个问题。5.7 版本 MySQL 的最佳解决方案;登录您的 mysql 控制台并使用以下命令更改您的密码:

ALTER USER `root`@`localhost` IDENTIFIED BY 'new_password', `root`@`localhost` PASSWORD EXPIRE NEVER;

回答by Marius.C

WARNING: this will allow any user to login

警告:这将允许任何用户登录

I had to try something else. Since my root password expired and altering was not an option because

我不得不尝试别的东西。由于我的 root 密码已过期,因此无法更改,因为

Column count of mysql.user is wrong. Expected 45, found 46. The table is probably corrupted

Column count of mysql.user is wrong. Expected 45, found 46. The table is probably corrupted

temporarly adding skip-grant-tablesunder [mysqld]in my.cnfand restarting mysql did the trick

即暂时将skip-grant-tables[mysqld]my.cnf并重新启动mysql的的伎俩

回答by Laurent Zminka

On Windows in phpmyadmin look in Variables: default_password_lifetime, and switch it to 0 (instead of 360), enjoy.

在 phpmyadmin 中的 Windows 中查看变量:default_password_lifetime,并将其切换为 0(而不是 360),享受。

Its possible than mySQL take again 360 days, so add in my.ini :

它可能比 mySQL 再次需要 360 天,所以在 my.ini 中添加:

[mysqld]
default_password_lifetime=0

And restart mysql.

并重新启动mysql。

回答by Dylan B

start MYSQL in safe mode

以安全模式启动MYSQL

mysqld_safe --skip-grant-tables &

Connect to MYSQL server

连接到MYSQL服务器

mysql -u root

run SQL commands to reset password:

运行 SQL 命令重置密码:

use mysql;
SET GLOBAL default_password_lifetime = 0;
SET PASSWORD = PASSWORD('new_password');

Last step, restart your mysql service

最后一步,重启你的mysql服务