views:

4262

answers:

4

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

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.

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.

Anyone have any ideas?

+2  A: 

You may need to switch from the mysqlnd driver to the previous mysql driver. This very likely will involve recompiling PHP, but as you've noted downgrading isn't an option, you might not be able to pull that off either.

Charles
Were you able to do this?
Nick Retallack
Me, or the OP? You may need to reply to his question, not my answer.
Charles
I marked this as the accepted answer since it seemed to be the best solution available. It still wasn't a solution for me though.
B T
Does that mean recompiling PHP with the older driver didn't work, or that you weren't able to recompile?
Charles
+5  A: 

edit: This only applies if you are in control of the MySQL server... if you're not take a look at http://stackoverflow.com/questions/1892607/mysql-password-hashing-method-old-vs-new

First check with the SQL query

SHOW VARIABLES LIKE 'old_passwords'

(in the MySQL command line client, HeidiSQL or whatever frontend 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 users tables. The MySQL will use the old authentication routine for these accounts. But you can simply set a new password for the account and the new routine will be used.
You can check which routine will be used by taking a look at the mysql.users table (with an account that has access to that table)

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 managements tools of the MySQL front end (if there are any) or

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 mysqlnd should be able to connect to the server.

see also: 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

VolkerK
Thanks for the detailed answer. I was able to connect with a gui client, and old_passwords is indeed "ON". I thought I had something when i "set old_password = OFF", but when i started a new session it was back on again.
B T
Oops, I didn't realize that you're not in control of the server (some kind of latent text blindness). In that case I think Charles is right. Or... maybe not all of the servers at bluesql.net are configured to use short password hashes. And maybe, if you ask them, you can be transferred to another server.
VolkerK
+1  A: 

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

sudo port install php5-mysql -mysqlnd +mysql5

This downgrades the mysql driver that php will use.

Chad Skeeters
A: 

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.

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:

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

This allowed me to connect successfully.

TehShrike