文档

PHP连接MySQL出现“cannot connect to MySQL 4.1+ using the old insecure authentication”

更新时间:

您的网站程序调试完成并上传到云虚拟主机后,连接云虚拟主机数据库时,提示“cannot connect to MySQL 4.1+ using the old insecure authentication”错误。本文介绍这种情况的可能原因和解决方案。

问题现象

报错信息如下。

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版本开始,不支持使用老旧的16位密码连接MySQL 4.1+版本的数据库(云虚拟主机提供的MySQL最低版本为5.1,满足条件)。若您的PHP版本为5.3+,且使用了16位的MySQL密码就会出现此错误。

解决方案

您需要将数据库加密模式设置为41位加密,以满足PHP 5.3+、MySQL 4.1+的运行要求。

此要求在主机控制台的高级环境设置 > PHP版本设置页面有提醒,敬请留意。

image

将加密模式设置为41位加密的方法如下。

  1. 主机管理平台 > 数据库信息页面,单击对应数据库的重置密码

  2. 在弹出的数据库密码重置对话框,点击确认

  3. 按照提示输入新密码。将其设为网站程序配置文件中的数据库密码,加密模式设置为41位。

  4. 点击确认