無法使用舊的身份驗證連接到MySQL 4.1+

[英]Cannot connect to MySQL 4.1+ using old authentication


I'm trying to connect to a mySQL database at http://bluesql.net, but when I try to connect, it gives this error:

我試圖連接到http://bluesql.net的mySQL數據庫,但是當我嘗試連接時,它會出現以下錯誤:

Connect Error (2000) mysqlnd cannot connect to MySQL 4.1+ using old authentication

I've looked into this, and it has to do with some old password scheme used before MySQL 4.1. Newer versions have the option to use old passwords, which I've read may cause this problem.

我已經研究過這個,它與MySQL 4.1之前使用的一些舊密碼方案有關。更新的版本可以選擇使用舊密碼,我讀過可能會導致這個問題。

I'm running php 5.3, and connecting with mySQLi (new mysqli(...)). I'm hoping I can do something in the code to connect to the DB at bluesql.net - clearly I don't control how their database is set up. Downgrading php versions isn't an option.

我正在運行php 5.3,並連接到mySQLi(新的mySQLi(…))。我希望我能在代碼中做點什么來連接到bluesql.net的DB——顯然我不能控制他們的數據庫是如何建立的。降級php版本不是一個選項。

Anyone have any ideas?

誰有什么好主意嗎?

7 个解决方案

#1


68  

edit: This only applies if you are in control of the MySQL server... if you're not take a look at Mysql password hashing method old vs new

編輯:這只適用於控制MySQL服務器的情況。如果您不了解Mysql密碼哈希方法,請查看新舊版本

First check with the SQL query

首先使用SQL查詢進行檢查

SHOW VARIABLES LIKE 'old_passwords'

(in the MySQL command line client, HeidiSQL or whatever front end you like) whether the server is set to use the old password schema by default. If this returns old_passwords,Off you just happen to have old password entries in the user table. The MySQL server will use the old authentication routine for these accounts. You can simply set a new password for the account and the new routine will be used.

(在MySQL命令行客戶端、HeidiSQL或其他前端)服務器是否設置為默認使用舊密碼模式。如果這返回old_password,則在user表中剛好有舊密碼條目。MySQL服務器將對這些帳戶使用舊的身份驗證例程。您可以簡單地為帳戶設置一個新密碼,並使用新的例程。

You can check which routine will be used by taking a look at the mysql.user table (with an account that has access to that table)

通過查看mysql,您可以檢查將使用哪個例程。用戶表(具有訪問該表的帳戶)

SELECT `User`, `Host`, Length(`Password`) FROM mysql.user

This will return 16 for accounts with old passwords and 41 for accounts with new passwords (and 0 for accounts with no password at all, you might want to take care of those as well).
Either use the user management tools of the MySQL front end (if there are any) or

這將返回16個有舊密碼的帳戶,41個有新密碼的帳戶(0個沒有密碼的帳戶,您可能也想要處理這些帳戶)。或者使用MySQL前端的用戶管理工具(如果有的話)或者

SET PASSWORD FOR 'User'@'Host'=PASSWORD('yourpassword');
FLUSH Privileges;

(replace User and Host with the values you got from the previous query.) Then check the length of the password again. It should be 41 now and your client (e.g. mysqlnd) should be able to connect to the server.

(用從上次查詢得到的值替換用戶和主機)。然后再次檢查密碼的長度。現在應該是41,您的客戶端(例如mysqlnd)應該能夠連接到服務器。

see also the MySQL documentation: * http://dev.mysql.com/doc/refman/5.0/en/old-client.html
* http://dev.mysql.com/doc/refman/5.0/en/password-hashing.html
* http://dev.mysql.com/doc/refman/5.0/en/set-password.html

請參閱MySQL文檔:* http://dev.sqmyl.com/doc/refman/5.0/en/old -client.html * http://dev.mysql.com/doc/refman/5.0/en/passwordhash.html

#2


60  

If you do not have control of the server

I just had this issue, and was able to work around it.

我剛剛遇到了這個問題,並且能夠解決它。

First, connect to the MySQL database with an older client that doesn't mind old_passwords. Connect using the user that your script will be using.

首先,使用不介意old_password的舊客戶機連接到MySQL數據庫。使用腳本將要使用的用戶進行連接。

Run these queries:

運行這些查詢:

SET SESSION old_passwords=FALSE;
SET PASSWORD = PASSWORD('[your password]');

In your PHP script, change your mysql_connect function to include the client flag 1:

在PHP腳本中,將mysql_connect函數更改為包含客戶端標志1:

define('CLIENT_LONG_PASSWORD', 1);
mysql_connect('[your server]', '[your username]', '[your password]', false, CLIENT_LONG_PASSWORD);

This allowed me to connect successfully.

這讓我成功地連接了。

Edit: as per Garland Pope's comment, it may not be necessary to set CLIENT_LONG_PASSWORD manually any more in your PHP code as of PHP 5.4!

編輯:根據Garland Pope的評論,可能不再需要在PHP 5.4中手動設置CLIENT_LONG_PASSWORD了!

Edit: courtesy of Antonio Bonifati, a PHP script to run the queries for you:

編輯:安東尼奧·博尼生命提供的一個PHP腳本,為您運行查詢:

<?php const DB = [ 'host' => '...', # localhost may not work on some hosting 
    'user' => '...',
    'pwd' => '...', ]; 

if (!mysql_connect(DB['host'], DB['user'], DB['pwd'])) {
    die(mysql_error());
} if (!mysql_query($query = 'SET SESSION old_passwords=FALSE')) {
    die($query);
} if (!mysql_query($query = "SET PASSWORD = PASSWORD('" . DB['pwd'] . "')")) {
    die($query);
}

echo "Excellent, mysqli will now work"; 
?>

#3


9  

you can do these line on your mysql query browser or something

你可以在mysql查詢瀏覽器上做這些

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;

note:your username and password

注意:您的用戶名和密碼

after that it should able to work. I just solved mine too

在那之后它應該可以工作了。我也解決了我的問題

#4


7  

On OSX, I used MacPorts to address the same problem when connecting to my siteground database. Siteground appears to be using 5.0.77mm0.1-log, but creating a new user account didn't fix the problem. This is what did

在OSX上,當連接到我的siteground數據庫時,我使用MacPorts解決相同的問題。Siteground似乎正在使用5.0.77 m0.1-log,但是創建一個新的用戶帳戶並沒有解決問題。這是什么

sudo port install php5-mysql -mysqlnd +mysql5

This downgrades the mysql driver that php will use.

這降低了php將使用的mysql驅動程序。

#5


2  

Had the same issue, but executing the queries alone will not help. To fix this I did the following,

有同樣的問題,但是單獨執行查詢不會有幫助。為了解決這個問題,我做了如下的事,

  1. Set old_passwords=0 in my.cnf file
  2. 在my.cnf文件中設置old_password =0
  3. Restart mysql
  4. 重新啟動mysql
  5. Login to mysql as root user
  6. 作為根用戶登錄到mysql。
  7. Execute FLUSH PRIVILEGES;
  8. 執行刷新權限;

#6


2  

If you do not have Administrator access to the MySQL Server configuration (i.e. you are using a hosting service), then there are 2 options to get this to work:

如果您沒有管理員訪問MySQL服務器配置(即您正在使用托管服務),那么有兩個選項可以讓它工作:

1) Request that the old_passwords option be set to false on the MySQL server

1)請求在MySQL服務器上將old_password選項設置為false

2) Downgrade PHP to 5.2.2 until option 1 occurs.

2)將PHP降級到5.2.2,直到出現選項1。

From what I've been able to find, the issue seems to be with how the MySQL account passwords are stored and if the 'old_passwords' setting is set to true. This causes a compatibility issue between MySQL and newer versions of PHP (5.3+) where PHP attempts to connect using a 41-character hash but the MySQL server is still storing account passwords using a 16-character hash.

根據我所能找到的,問題似乎在於MySQL帳戶密碼的存儲方式以及“old_password”設置是否為true。這導致了MySQL與更新版本的PHP(5.3+)之間的兼容性問題,在這些版本中,PHP試圖使用41個字符的散列進行連接,但MySQL服務器仍然使用16個字符的散列存儲帳戶密碼。

This incompatibility was brought about by the changing of the hashing method used in MySQL 4.1 which allows for both short and long hash lengths (Scenario 2 on this page from the MySQL site: http://dev.mysql.com/doc/refman/5.5/en/password-hashing.html) and the inclusion of the MySQL Native Driver in PHP 5.3 (backwards compatibility issue documented on bullet 7 of this page from the PHP documentation: http://www.php.net/manual/en/migration53.incompatible.php).

這種不兼容性帶來改變的哈希方法中使用MySQL 4.1允許短期和長期散列的長度(場景2這個頁面上從MySQL網站:http://dev.mysql.com/doc/refman/5.5/en/password-hashing.html)和MySQL的包含本地司機在PHP 5.3(向后兼容性問題記錄在這個頁面的子彈7從PHP文檔:http://www.php.net/manual/en/migration53.incompatible.php)。

#7


0  

IF,

如果,

  1. You are using a shared hosting, and don't have root access.
  2. 您正在使用共享主機,並且沒有root訪問權限。
  3. you are getting the said error while connecting to a remote database ie: not localhost.
  4. 當連接到遠程數據庫ie:而不是localhost時,您將獲得上述錯誤。
  5. and your using Xampp.
  6. 和你使用Xampp。
  7. and the code is running fine on live server, but the issue is only on your development machine running xampp.
  8. 並且代碼在活動服務器上運行良好,但是問題只出現在運行xampp的開發機器上。

Then,

然后,

It is highly recommended that you install xampp 1.7.0 . Download Link

強烈建議您安裝xampp 1.7.0。下載鏈接

Note: This is not a solution to the above problem, but a FIX which would allow you to continue with your development.

注意:這不是解決上述問題的方法,而是一個可以讓您繼續開發的解決方案。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/10/16/b0fece65243c80e1bd80c69520cd8d43.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com