【问题标题】:Windows 7 PHP MySQL Connection Issues [duplicate]Windows 7 PHP MySQL连接问题[重复]
【发布时间】:2011-06-15 23:27:55
【问题描述】:

当我运行$conn = mysql_connect($host, $user, $pass); 时,我能够连接到数据库,但是当我执行var_dump($conn) 时,我返回bool(true),这限制了我与多个服务器的多个连接。

这台计算机上的原始设置是带有 PHP 5.2 版本的 XAMPP,该版本已通过 PHP 安装程序升级到 PHP 5.3.4。它可以毫无问题地连接到其本地数据库(除了返回布尔值而不是资源链接标识符),但无法连接到任何远程机器(并且已确认连接到远程机器的能力)。在无法提出解决方案的情况下,我升级到内置 PHP 5.3.1 的 XAMPP 版本。重新安装 XAMPP 后出现完全相同的错误,这让我相信这是一个更大的问题.

编辑 1 **

迁移到全新安装的 Windows 并安装 XAMPP 并尝试运行 mysql_connect 到远程服务器(PHP 5.3.1)我得到同样的错误:

Warning: mysql_connect() [function.mysql-connect]: Premature end of data (mysqlnd_wireprotocol.c:554) in [Removed] on line 2

Warning: mysql_connect() [function.mysql-connect]: OK packet 1 bytes shorter than expected in [Removed]p on line 2

Warning: mysql_connect() [function.mysql-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 in [Removed] on line 2

【问题讨论】:

标签: mysql windows-7 php mysql-connect


【解决方案1】:

检查my.cnf 文件中的old_passwords 选项。

http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_old-passwords

如果由于某种原因无法切换到新密码,则不能使用mysqlnd 作为 MySQL 驱动程序,需要切换回旧密码。

更多关于mysqlnd的信息

http://dev.mysql.com/downloads/connector/php-mysqlnd/

【讨论】:

  • 我已经尝试了old_passwords 建议(只是为了尽职调查而重试)无济于事,我目前正在加载 mysqlnd,但在 5.3.1 和 5.3.4 中的行为都没有变化
  • 这可以通过将您的 XAMPP 版本从 1.7.4 降级到 1.7.3 来解决。显然,当前发布的版本是 beta 版本,尽管它目前没有被标记为 beta 版本。
【解决方案2】:

关于您在编辑中发布的错误,我在使用 PHP 5.3.5 连接到 Linux 上的 MySQL 5.0.45 时在 Windows 7 上遇到了同样的错误。我的解决方案是在 my.cnf 中禁用“old_passwords”并运行

set password = password('my password');

错误消息没有明确说明您必须执行这两个步骤才能解决问题。希望这会有所帮助。

【讨论】:

    【解决方案3】:

    当你想修改你的密码并且服务器一直在生成 16 字节的哈希时,你可以尝试如下:

    1) 自己生成 41bytes 哈希(使用一些哈希生成器网站) 例如 密码:'qwerty' 哈希:'aa1420f182e88b9e5f874f6fbe7459291e8f4601'

    2) 更改密码 为“用户名”设置密码=“*aa1420f182e88b9e5f874f6fbe7459291e8f4601”

    现在您应该可以使用新的身份验证方法连接到数据库了

    【讨论】:

    • 尝试了大多数其他建议。这是唯一对我有帮助的答案。谢谢
    【解决方案4】:

    我几乎尝试了这里(和其他地方)列出的所有内容,但没有成功,直到我找到了这个:

    SET old_passwords = 0; UPDATE mysql.user SET Password = PASSWORD('testpass') WHERE User = 'testuser' limit 1; SELECT LENGTH(Password) FROM mysql.user WHERE User = 'testuser'; 刷新特权;

    把它放到你的mysql客户端或者phpmyadmin中,把testpass改成你的数据库登录密码,把testuser改成你的数据库登录用户,执行查询。巨大的成功!问题解决了。

    【讨论】:

      猜你喜欢
      • 2011-01-17
      • 2015-12-16
      • 2020-11-20
      • 1970-01-01
      • 2020-01-22
      • 2011-06-03
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多