我有一个专用服务器,它已经安装并运行良好一段时间了,如下所示。我们称此服务器为 1。
MySQL 5.0.95 PHP 5.2.17
使用此方法从 PHP 创建到数据库的连接运行正常:
mysql_connect($IPAddress,$DBUser,$DBPassword);
@mysql_select_db($database) or die( "Unable to select database");
现在我还有第二个专用服务器,我们称之为服务器 2,它连接到上述服务器上的数据库,直到今天它都运行良好。我所做的是将 PHP 更新到版本 5.3.19,现在我收到的错误是:
Could not connect: 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
我已经尝试运行 SET PASSWORD 命令,但它仍然不起作用。我也试过将旧密码标志设置为 0,但这也不起作用。
我错过了什么吗?在服务器 1 上一切正常,只是服务器 2 不工作。
最佳答案
删除或注释掉文件“my.cnf”(例如/etc/my.cnf)中的以下行:
old_passwords = 1
这将阻止 MySQL 使用旧密码,现在我打赌如果你运行查询 - SELECT user, Length(Password) FROM mysql.user;
- 你会看到你的用户名可能有两个条目,一个 16 个字符和一个 41(41 是您最近运行的查询 SET PASSWORD
。)
在 old_passwords
被删除/注释掉之后,您需要重新启动 MySQL,否则它将继续使用 old_passwords
一旦 MySQL 重新启动,您可能需要再次运行以下查询:
UPDATE mysql.user SET Password = PASSWORD('yourPassword!') WHERE user = 'yourUser';
&
FLUSH Privileges;
关于PHP MySQL 连接查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14459282/