PHP MySQL 连接查询

标签 php mysql connection

我有一个专用服务器,它已经安装并运行良好一段时间了,如下所示。我们称此服务器为 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/

相关文章:

php - 当我内爆异常(exception)页面时 Laravel 中间件错误

mysql - 优化 mysql 查询以获取每个用户 "unseen"个条目

android - Android 和 MySQL/PHP 数据库连接问题

java - 服务器地址和客户端地址不同

php - 我是否需要联接才能从此表中检索信息?

php - 使用 PHP 和 MySql 中的印地语 (Unicode) 内容将数据导出到 Excel

PHP - 获取可用数据库名称的下拉列表。

PHP MySQL 触发器 - 如何将变量传递给触发器?

mysql - 插入 othertbl SELECT * tbl

connection - SQL Anywhere 11,JZ0C0 : Connection is already closed