Many people who are upgrading their databases, and PHP version of late will have come across an error such as this
Or, if using PDO, like good programmers should, the error is prefixed with the error
The error occurs for a multiplicity of reasons, which conspire to give this error. PHP version 5.3 and above, now uses the mysqlnd driver by default, and as such uses the newer password hashing algorithm. A quick check will show the issue quite clearly.
The above query will show
As you can see, the password lengths are 16, and the new password hashing for MySQL versions 4.1 and greater uses a 41 character hash. The PHP mysqlnd extension requires a 41 character password hash. Oh the humanity!
To see a list of password which are in the new and old formats, use this command
The results will look something like this..
+----------+--------------------+ | user | Length(`Password`) | +----------+--------------------+ | root | 41 | | root | 16 | | kevin | 16 | | billy | 16 | +----------+--------------------+
Some folks have reported varying result using various methods. Here is what worked for me.
Firstly, open up your my.conf file and comment out the following line
Restart MySQL. this will ensure MySQL never uses the old passwords again.
This is one way to update the passwords in the user table. Be sure to flush the priviges after.
Another fix is to things this way.
Now you should be able to connect with php and the mysqlnd driver
看不懂英文的同学,可以看这个有一点简单译文的。