开发者

Zend Framework: Authentication, MySQL errors when switching from SQLite

I'm switching my app from using SQLite to MySQL. It works with SQLite and it's not working now that I've changed it to use MySQL. Here's the error message I'm getting:

Message: SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using old authentication

What does this mean?

Note: I'm running this locally running Snow Leopard, trying to access a remote database.

It's also dumping my username and password to the 开发者_如何学运维screen in plain text in the request parameters which is a little unsettling.


Are you running PHP 5.3? mysqlnd is the new native MySQL driver for PHP (ext/mysql, ext/mysqli and PDO make use of it, so it is not a new API but a new way how the three different APIs communicate with the MySQL server) - here is a nice article about mysqlnd.

The problem now is that your MySQL server uses an old authentication mechanism which mysqlnd is not able to comply with. mysqlnd needs the new 41 bytes password that was introduced with MySQL 4.1 (so you cannot connect to MySQL servers < 4.1). To update your user table to use the new password scheme you have to use the SET PASSWORD command on your MySQL server, e.g.:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypassword');

This changes the password scheme and will allow you to connect with mysqlnd. Here Thomas Rabaix describes exactly the same problem - just for reference.


Andrew I think you have a problem with your MySQL client using old authentication.

You should make sure your PDO is using the last mysqlclient library.

you might want to test a PDO sample first to make sure everything is fine and after play with ZF.

 $db = new PDO("mysql:host=$host;dbname=$database", 
            $username, $password);

On your remark for Usernamer/Password , the Zend Framework documentation is stating that is the developer not to show those errors to user by setting different level of configuration in production and development. Zend_config is there for that, plus the error catching controller.


Use this to solve your problem :)

SET SESSION old_passwords = 0;
SELECT @@global.old_passwords, @@session.old_passwords, Length(PASSWORD('abc'));
SET PASSWORD = PASSWORD('abc')

Good Luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜