Skip to content

Instantly share code, notes, and snippets.

@bastman
Created May 3, 2016 14:12
Show Gist options
  • Save bastman/5c8dc4c6af334e7b4144cb89f69e45ef to your computer and use it in GitHub Desktop.
Save bastman/5c8dc4c6af334e7b4144cb89f69e45ef to your computer and use it in GitHub Desktop.
How to solve PDOException: SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication.

mysql compatibility issues

While porting old php/mysql stack to php 5.6 & mysqlnd - you may have issues regarding the old mysql password hashing strategie

see: - https://dev.mysql.com/doc/refman/5.6/en/account-upgrades.html - http://code.openark.org/blog/mysql/upgrading-passwords-from-old_passwords-to-new-passwords

Example Error (using pdo):

DB ERROR! SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file 
details: {"class":"PDOException","message":"SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file","data":null,"debug":null}

Solution:

use mysql client of your choice
and create an new user/password


[email protected]> SET SESSION old_passwords=0;
Query OK, 0 rows affected (0.00 sec)
[email protected]> SET PASSWORD FOR 'webuser'@'localhost' = PASSWORD('123456')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment