Yeah I know this is a common question. But I tried everything and I can’t get this solved.
So I am using plesk 12.5 and I can login to mysql from terminal with this script which uses the hashed password:
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin
I can even login when I add -h localhost to it.
But I cannot login when I login from a php script.
<?php
$mysqli = new mysqli("localhost/ip adress", "admin", "plesk encrypted password", "database");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
What I have tried:
- I tried to change the password in mysql
- I have tried to update mysql (it’s up to date)
- I have tried to grant privileges
- I tried to get access with a new SQL user
- I have tried to enter all different passwords I have seen, so I don’t think it’s a password problem (EDIT)
EDIT: Thanks for the posts, it seems that the following has nothing to do with the issue above.
But after all this there is one thing that is really bugging me:
When I type the following command in mysql:
show grants;
I get the following:
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY PASSWORD 'NOT the plesk cleartext password'
The password displayed starts with an asterix (*) followed by random text and numbers.
I tried to get access with this password, but it isn’t recognized at all.
I think this is weird, but I still can’t find a solution.
2
Answers
$mysqli = new mysqli(“localhost/ip adress”, “admin”, “real password dyou entered not the encrypted one”, “database”);
mysql and any other decent tools won’t store your password neither in plaintext nor encrypted format.It will hash and destroy the string you entered as password so it can get to that string everytime you input the right password with no chance of recovering it from mysql itself.
There is no problem with your grant command, that’s what it’s supposed to return.
here is an easy example, not the actual process:
my password is 123456
the encrypted format is abcdef
when I input the encrypted format (abcdef), mysql then converts it to 123456
now that it has your plaintext password, it will hash it with mysql’s own methods, like removing a character or shifting the string sideways or adding to the ASCII value using the fibonacci sequence, or any other method the programmer chooses to do.
let’s say my hashing method is removing the first and last characters and then adding 2 to the ASCII val of the remaining
line1: 123456
line2: 2345
line3: 4567
4567 is my hashed password, so show grants will display:
and not 123456