Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't connect to MySQL when using password

Status
Not open for further replies.

gxydas

Programmer
Jan 15, 2005
76
GR
Hi all,
I use PHP 4, MySQL 4.1 and Apache 1.3.19. The problem is that i can't connect to MySql when i use a user with a password.
$db= mysql_pconnect('localhost', 'user', '123');

The problem does not occurs when the user has no password.
$db= mysql_pconnect('localhost', 'user1');
Thanks!

 
you probably have not granted the right permissions to 'user' within mysql.

use mysqlcc (or equivalent) from the website to check the permissions. it's a clunky interface but works.
 
jpadie,
when i remove the password from 'user' it works just fine. The 'user' has all priviledges in the database.
 
in your post above you referenced two users

1. user, with password 123
2. user1 with no password

are you also saying that the user called "user" has been created with no password?
 
I use MySQL Administrator to delete or to put a password to user called "user". When the "user" has no password the connection works. But when I put a password (using MySQL Administrator) to the "user" the connection can't be done.
 
then the password is not being correctly applied.

when using mysql admin are you administering the dbs with root privileges?
 
The password is correct. I've tried that with more than 1 users. I've created more users but the problem is the same.
Yes I have root priviledges.
Maybe the MySQL 4.1 uses an encryption that I don't know.
 
im not saying that the password is not correct! just that it is, for some reason, not being applied to the user name when you create that user.

it's difficult to help with this kind of query. could you test by running this code (this will help ascertain whether your user table migth be corrupt

Code:
$username = "" ; //username for password
$password = "" ;// userpassword for database
$rootpass = "";// password for root db user
$sql = 
"GRANT ALL 
    ON *.* 
    TO $username IDENTIFIED BY PASSWORD '$password';
";
mysql_pconnect ($host, "root", $rootpass)
  or die ("unable to connect to server. ".mysql_error());
mysql_query($sql)
  or die ("Query error. SQL was: <br /> $sql <br />. Mysql error was: ".mysql_error());
 
This the result of your code:
Mysql error was: Password hash should be a 41-digit hexadecimal number
 
so sorry - sloppy coding again (suffering from flu...)

Code:
$username = "" ; //username for password
$password = "" ;// userpassword for database
$rootpass = "";// password for root db user
$sql = 
"GRANT ALL 
    ON *.* 
    TO $username IDENTIFIED BY '$password';
"; //PASSWORD directive removed
mysql_pconnect ($host, "root", $rootpass)
  or die ("unable to connect to server. ".mysql_error());
mysql_query($sql)
  or die ("Query error. SQL was: <br /> $sql <br />. Mysql error was: ".mysql_error());
 
Your code worked ok.
The error i'm getting now when i'm trying to connect to db with the user is listed below:

Warning: Client does not support authentication protocol requested by server; consider upgrading MySQL client
 
what client are you using? the embedded php library or a third party client?

this is also heading towards a pure mysql issue and you may find more knowledgable people (certainly than me!) in the mysql forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top