June 2014
« Feb   Jul »

PHP 5.5 : MySQL error – The server requested authentication method unknown to the client

Recently I had to upgrade the php version to 5.5 on one of the servers for the enhancement. All the php hosted sites showing database errors after the switching to new PHP version. The error is shown below,

Could not connect: The server requested authentication method unknown to the client. So I had to revert it to the older version in order to ensure the service uptime.

Problem : The MySQL account you’re using probably has an old 16 character long password (hash).The new mysqlnd library necessitates the use of MySQL 4.1’s newer 41-byte password format. Continued use of the old 16-byte passwords will cause mysql_connect() and similar functions to emit the error, “mysqlnd cannot connect to MySQL 4.1+ using old authentication.”

Solution : you may need to update all users password to use newer 41-byte password format. The MySQL connector (mysqlnd) on PHP 5.5 version accept only 41 byte password only.

1. Disable old password support on MySQL
Comment the line old_passwords=1 in /etc/my.cnf file

Eg : [liju@mail ~]$ grep "old_passwords"  /etc/my.cnf
[liju@mail ~]$

2. Collect all the user credentials and convert the password to 41 bytes long.

Suppose My user name is liju, password is “my_pass” and I have access to the database “mydb“. Then you need to execute this command from mysql console.

#mysql>grant all on  mydb.* to liju@localhost identified by '_my_pass';
#mysql>SET PASSWORD FOR 'nanowebtechuser'@'localhost' = PASSWORD('my_pass');

Then you should be seeing the new password is accepting on php 5.5 version.

~njoy 🙂

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>