php - 错误 : mysqlnd cannot connect to MySQL 4. 1+ 使用旧的不安全身份验证

标签 php mysql sql database database-connection

我收到以下错误:

Database connection failed: 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

我在本地机器上使用 PHP 5.3.8 和 MySQL 5.5.16,而我的主机(媒体库)正在运行 PHP 5.3 MySQL 5.0.51a。实时服务器上的版本比我机器上的版本旧。

如何修复此错误并从本地计算机连接到 MySQL?

我知道有与此类似的帖子,但我已经尝试了所有帖子,但没有一个有效。

最佳答案

  • 删除或评论 my.cnf 中的 old_passwords = 1

重启 MySQL。如果您不这样做,MySQL 将继续使用旧密码格式,这意味着您无法使用内置的 PASSWORD() 散列函数升级密码。

旧密码哈希是 16 个字符,新密码哈希是 41 个字符。

  • 连接到数据库,并运行以下查询:

    SELECT user, Length(`Password`) FROM  `mysql`.`user`;
    

这将显示哪些密码采用旧格式,例如:

+----------+--------------------+
| user     | Length(`Password`) |
+----------+--------------------+
| root     |                 41 |
| root     |                 16 |
| user2    |                 16 |
| user2    |                 16 |
+----------+--------------------+

Notice here that each user can have multiple rows (one for each different host specification).

To update the password for each user, run the following:

UPDATE mysql.user SET Password = PASSWORD('password') WHERE user = 'username';

最后,刷新权限:

FLUSH PRIVILEGES;

来源:How to fix "mysqlnd cannot connect to MySQL 4.1+ using old authentication" on PHP5.3

关于php - 错误 : mysqlnd cannot connect to MySQL 4. 1+ 使用旧的不安全身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8831183/

相关文章:

sql - 根据 SQL 或 R 中的某些条件复制行

SQL排除没有子查询的行

php - 如何找到页面加载时调用的所有 php 文件的列表?

java - 如何使用Hibernate JAVA调用mysql存储过程

sql - 在 SQL Server 中排序递归结果集

mysql - 优化MySQL中的JOIN查询

mysql - phpMyAdmin 是否有内置安全性

php - 实现撤消和重做功能 javascript 和 php

php - 在自定义函数中从 WooCommerce 动态获取优惠券代码

php - 如何为新闻门户创建 CMS?