PHP 5.4 PDO 无法使用旧的不安全身份验证连接到 MySQL 4.1+

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10420831/
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-24 22:06:58  来源:igfitidea点击:

PHP 5.4 PDO could not connect to MySQL 4.1+ using the old insecure authentication

phpmysqlpdo

提问by Ozzy

I know there are a tonne of similar questions, in fact I've read all (9) of them.

我知道有很多类似的问题,事实上我已经阅读了所有 (9) 个问题。

However, none of them solve my problem.

但是,它们都没有解决我的问题。

I have a shared-hosting package (the minimum). What's included in my package is the domain name, and a separate IP address where the MySQL server is hosted. For development, I'm using http://localhost/with PHP 5.4's development server, and I'm using the MySQL server I get in my hosting package.

我有一个共享主机包(最低限度)。我的包中包含的是域名和托管 MySQL 服务器的单独 IP 地址。对于开发,我使用的http://localhost/是 PHP 5.4 的开发服务器,我使用的是我的托管包中的 MySQL 服务器。

The problem arises only on my PC, because I have installed PHP 5.4, but my web host has installed PHP 5.2.17 and won't upgrade. The MySQL server is on MySQL 5.1.50.

问题仅出现在我的 PC 上,因为我已经安装了 PHP 5.4,但是我的网络主机已经安装了 PHP 5.2.17 并且不会升级。MySQL 服务器在 MySQL 5.1.50 上。

Luckily, phpMyAdmin has a built-in "Change Password" feature.

幸运的是,phpMyAdmin 有一个内置的“更改密码”功能。

There are two hashing options in phpMyAdmin for changing a password:

phpMyAdmin 中有两个用于更改密码的散列选项:

  • MySQL 4.1+
  • MySQL 4.0 compatible
  • MySQL 4.1+
  • MySQL 4.0 兼容

I changed the password with the MySQL 4.1+ option, and it confirmed the update was successful.

我使用 MySQL 4.1+ 选项更改了密码,并确认更新成功。

The profile has been updated. SET PASSWORD = PASSWORD( '***' )

个人资料已更新。 SET PASSWORD = PASSWORD( '***' )

However, when I perform this query:

但是,当我执行此查询时:

SELECT @@global.old_passwords, @@session.old_passwords, Length(PASSWORD('abc'));

It tells me the password length is still 16. Output:

它告诉我密码长度仍然是 16。输出:

1     1     16
1     1     16

And so the problem persists.

所以问题仍然存在。

Could not connect to database. SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file

无法连接到数据库。SQLSTATE[HY000] [2000] mysqlnd 无法使用旧的不安全身份验证连接到 MySQL 4.1+。请使用管理工具通过命令 SET PASSWORD = PASSWORD('your_existing_password') 重置您的密码。这将在 mysql.user 中存储一个新的、更安全的哈希值。如果在 PHP 5.2 或更早版本执行的其他脚本中使用了此用户,您可能需要从 my.cnf 文件中删除 old-passwords 标志

I've also tried to do these queries, when logged in with the DBO user in phpMyAdmin:

当使用 phpMyAdmin 中的 DBO 用户登录时,我也尝试执行这些查询:

SET SESSION old_passwords=0; 
[phpMyAdmin reloads to the home screen, but the value remains = 1]

SET GLOBAL old_passwords = 0;
#1227 - Access denied; you need the SUPER privilege for this operation

FLUSH PRIVILEGES;
#1227 - Access denied; you need the RELOAD privilege for this operation

This is contradictory to what is stated in the webhost's menu for setting the DBO user:

这与用于设置 DBO 用户的网络主机菜单中所述的内容相矛盾:

Database Owner
When you create a new database, you need to specify a Database Owner (DBO) User, which will have
full administrator access to the database.

数据库所有者
创建新数据库时,您需要指定一个数据库所有者 (DBO) 用户,该用户将拥有
对数据库的完全管理员访问权限。

Is this something I have to take up with my webhosts? Or can it be solved by my DBO user? Otherwise can this be bypassed in PHP? (since it works with PHP 5.2.17 but not PHP 5.4)

这是我必须与我的虚拟主机商解决的问题吗?或者它可以由我的 DBO 用户解决吗?否则可以在PHP中绕过吗?(因为它适用于 PHP 5.2.17 但不适用于 PHP 5.4)

回答by Ozzy

SOLVED!

解决了!

Although the SET SESSION old_passwords=0;wasn't working in phpMyAdmin.

虽然SET SESSION old_passwords=0;在 phpMyAdmin 中不起作用。

I downloaded the MySQL GUI Toolsand used the MySQL Query Browser to execute the same command on non-DBO user:

我下载了MySQL GUI 工具并使用 MySQL 查询浏览器在非 DBO 用户上执行相同的命令:

SET SESSION old_passwords = 0;

SET SESSION old_passwords = 0;

SELECT @@global.old_passwords, @@session.old_passwords, Length(PASSWORD('abc'));

SELECT @@global.old_passwords, @@session.old_passwords, Length(PASSWORD('abc'));

now returned:

现在返回:

1      0      41

So I simply changed the password:

所以我简单地更改了密码:

SET PASSWORD = PASSWORD('my_old_password')

SET PASSWORD = PASSWORD('my_old_password')

And now PHP 5.4 PDO connects to the database with that user!

现在 PHP 5.4 PDO 连接到该用户的数据库!

回答by Brian

In phpMyAdmin, setting the session variable will work, but the call to the password function must occur in the same session/execution.

在 中phpMyAdmin,设置会话变量将起作用,但对密码函数的调用必须发生在同一个会话/执行中。

For example, if I execute:

例如,如果我执行:

SET SESSION old_passwords = 0;
SET PASSWORD = PASSWORD('notagoodpassword');

It will correctly set it.

它会正确设置它。

回答by wolki

this solution worked: SET SESSION old_passwords = 0;

这个解决方案有效:SET SESSION old_passwords = 0;

BUT: I had to drop the "old" userfrosting table afterwards and create it new - then it worked like a charm.

但是:之后我不得不放弃“旧”的用户霜表并创建新的 - 然后它就像一个魅力。