This question already has an answer here:
这个问题已经有了答案:
- Cannot connect to MySQL 4.1+ using old authentication 7 answers
- 无法连接到MySQL 4.1+使用旧的认证7答案。
When I run $conn = mysql_connect($host, $user, $pass);
I am able to get a connection to the database but when i do a var_dump($conn)
I get back bool(true)
which is limiting me from having multiple connection to multiple servers.
当我运行$conn = mysql_connect($host, $user, $pass)时;我可以连接到数据库,但是当我执行var_dump($conn)时,我得到了bool(true),这限制了我从多个服务器连接到多个服务器。
The original setup on this computer was XAMPP with a version of PHP 5.2 that was upgraded to PHP 5.3.4 via the PHP installer. It could connect to its local database with no problem (other than returning a boolean instead of the resource link identifier) but could not connect to any remote machines (and the ability to connect to remote machines has been confirmed). Without being able to come up with a solution, i upgraded to a version of XAMPP that has PHP 5.3.1 built in. I get exactly the same error after a fresh reinstall of XAMPP which is leading me to believe that this is a larger issue.
这台计算机的原始设置是XAMPP,它的版本是PHP 5.2,通过PHP安装程序升级到PHP 5.3.4。它可以连接到本地数据库,没有问题(除了返回一个布尔值而不是资源链接标识符),但是不能连接到任何远程机器(以及连接到远程机器的能力已经得到确认)。如果没有找到解决方案,我就升级到XAMPP的版本,它内置了PHP 5.3.1。在重新安装XAMPP之后,我得到了完全相同的错误,这让我相信这是一个更大的问题。
Edit 1 **
编辑1 * *
Moving to a clean install of windows and installing XAMPP and trying to run a mysql_connect to a remote server (PHP 5.3.1) i get the same error:
移动到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
4 个解决方案
#1
4
Check old_passwords
option in your my.cnf
file.
在my.cnf文件中检查old_password选项。
http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_old-passwords
http://dev.mysql.com/doc/refman/5.0/en/server-options.html option_mysqld_old-passwords
If for whatever reason you can't switch to new passwords, you can't use mysqlnd
as your MySQL driver, and need to switch back to the older one.
如果你不能切换到新的密码,你就不能使用mysqlnd作为你的MySQL驱动程序,并且需要切换回旧密码。
Some more information about mysqlnd
关于mysqlnd的更多信息。
http://dev.mysql.com/downloads/connector/php-mysqlnd/
http://dev.mysql.com/downloads/connector/php-mysqlnd/
#2
4
Regarding the error posted in your edit, I had been getting the same error on Windows 7 using PHP 5.3.5 when connecting to MySQL 5.0.45 on Linux. The solution for me was to disable "old_passwords" in my.cnf AND run
关于你编辑的错误,我在Windows 7上使用PHP 5.3.5在Linux上连接到MySQL 5.0.45时得到了相同的错误。我的解决方案是在my.cnf中禁用“old_password”,然后运行。
set password = password('my password');
The error message doesn't make it clear that you have to do both steps in order to fix the problem. Hope this helps.
错误消息并没有明确说明您必须执行这两个步骤才能解决问题。希望这个有帮助。
#3
2
when you want to change your password and the server keeps on generating 16 bytes hashes, you may try as following:
当您想要更改您的密码,并且服务器继续生成16个字节的散列时,您可以尝试如下所示:
1) generate 41bytes hash by yourself (using some hash generator website) for example password: 'qwerty' hash: 'aa1420f182e88b9e5f874f6fbe7459291e8f4601'
1)通过自己生成41字节的散列(使用某个hash生成器网站),例如:'qwerty' hash: 'aa1420f182e88b9e5f874f6fbe7459291e8f4601'
2) change the password SET PASSWORD FOR 'username' = '*aa1420f182e88b9e5f874f6fbe7459291e8f4601'
2)更改“用户名”的密码设置密码为“* aa1420f182e88b9e5f874f6f6f6f6f6f4601”
now you should be able to connect to the database using the new authentication method
现在,您应该能够使用新的身份验证方法连接到数据库。
#4
0
I tried just about everything listed here (and elsewhere) to no avail till I found this:
我尝试了在这里(和其他地方)所列的一切,直到我发现了这个:
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'; FLUSH PRIVILEGES;
设置old_passwords = 0;更新mysql。用户设置密码=密码('testpass'),用户= 'testuser' limit 1;从mysql选择长度(密码)。用户= 'testuser';冲洗特权;
Drop that into your mysql client or phpmyadmin and change the testpass to your DB login password and the testuser to your DB login user, execute query. Great success! problem solved.
将其放入mysql客户端或phpmyadmin中,并将testpass更改为您的DB登录密码,并将testuser更改为您的DB登录用户,执行查询。巨大的成功!问题解决了。
#1
4
Check old_passwords
option in your my.cnf
file.
在my.cnf文件中检查old_password选项。
http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_old-passwords
http://dev.mysql.com/doc/refman/5.0/en/server-options.html option_mysqld_old-passwords
If for whatever reason you can't switch to new passwords, you can't use mysqlnd
as your MySQL driver, and need to switch back to the older one.
如果你不能切换到新的密码,你就不能使用mysqlnd作为你的MySQL驱动程序,并且需要切换回旧密码。
Some more information about mysqlnd
关于mysqlnd的更多信息。
http://dev.mysql.com/downloads/connector/php-mysqlnd/
http://dev.mysql.com/downloads/connector/php-mysqlnd/
#2
4
Regarding the error posted in your edit, I had been getting the same error on Windows 7 using PHP 5.3.5 when connecting to MySQL 5.0.45 on Linux. The solution for me was to disable "old_passwords" in my.cnf AND run
关于你编辑的错误,我在Windows 7上使用PHP 5.3.5在Linux上连接到MySQL 5.0.45时得到了相同的错误。我的解决方案是在my.cnf中禁用“old_password”,然后运行。
set password = password('my password');
The error message doesn't make it clear that you have to do both steps in order to fix the problem. Hope this helps.
错误消息并没有明确说明您必须执行这两个步骤才能解决问题。希望这个有帮助。
#3
2
when you want to change your password and the server keeps on generating 16 bytes hashes, you may try as following:
当您想要更改您的密码,并且服务器继续生成16个字节的散列时,您可以尝试如下所示:
1) generate 41bytes hash by yourself (using some hash generator website) for example password: 'qwerty' hash: 'aa1420f182e88b9e5f874f6fbe7459291e8f4601'
1)通过自己生成41字节的散列(使用某个hash生成器网站),例如:'qwerty' hash: 'aa1420f182e88b9e5f874f6fbe7459291e8f4601'
2) change the password SET PASSWORD FOR 'username' = '*aa1420f182e88b9e5f874f6fbe7459291e8f4601'
2)更改“用户名”的密码设置密码为“* aa1420f182e88b9e5f874f6f6f6f6f6f4601”
now you should be able to connect to the database using the new authentication method
现在,您应该能够使用新的身份验证方法连接到数据库。
#4
0
I tried just about everything listed here (and elsewhere) to no avail till I found this:
我尝试了在这里(和其他地方)所列的一切,直到我发现了这个:
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'; FLUSH PRIVILEGES;
设置old_passwords = 0;更新mysql。用户设置密码=密码('testpass'),用户= 'testuser' limit 1;从mysql选择长度(密码)。用户= 'testuser';冲洗特权;
Drop that into your mysql client or phpmyadmin and change the testpass to your DB login password and the testuser to your DB login user, execute query. Great success! problem solved.
将其放入mysql客户端或phpmyadmin中,并将testpass更改为您的DB登录密码,并将testuser更改为您的DB登录用户,执行查询。巨大的成功!问题解决了。