SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication

 

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

This is a small script, made by Antonio Bonifati and found at StackOverflow Cannot connect to MySQL 4.1+ using old authentication  that will update your password and it will solve this problem for you.

<?php

$hostname = '127.0.0.1';
$database = 'database_name';
$username = 'database_username';
$password = 'password';

if (!mysql_connect($hostname, $username, $password)) {
 die(mysql_error());
} if (!mysql_query($query = 'SET SESSION old_passwords=FALSE')) {
 die($query);
} if (!mysql_query($query = "SET PASSWORD = PASSWORD('" .$password . "')")) {
 die($query);
}
echo "Excellent, mysqli will now work";

exit();
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.