0

I have phpMyAdmin running with MAMP, and I am finding it impossible to use mysql_connect().

$_db_connect = mysql_connect("root", "localhost");

Produces an error in php_error.log: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'root'@'localhost' (using password: NO) in /....../common.lib.php on line 19

I've checked out the privileges:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION

GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION

and I am simply stumped. I've created new users with passwords just to get the same result. Strangely it always says (using password: NO), even when I attempt to connect as a user witha password:

$_db_connect = mysql_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD);

Any advice is welcomed. Thanks!

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
kingkong
  • 13
  • 1
  • 1
  • 3

5 Answers5

4

That error message for dummies:

Access denied for user 'root'@'localhost' (using password: NO)

It has three parts, each of it contains important information. Let's see:

  1. Access denied - In plain words, this means: Get lost! Don't try to connect to me.
  2. for user 'root'@'localhost' - That says who is denied access, that user. The name: root and at (@) the following server: localhost.
  3. using password: NO - Just some nice additional information that when trying to access and giving the user-name, no password was used.

So now on with the privileges you have:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'
 IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B'
 WITH GRANT OPTION
GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION

It basically says, that the user 'root'@'localhost' needs to use a password to get access. As the error message tells you, you are not using a password. So that is likely to be the cause of the error, the password is missing.

Add the password and try again.

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
hakre
  • 193,403
  • 52
  • 435
  • 836
3

You forgot to enter the passwort. If I guess right then is the hash 81F5E21E35407D884A6CD4A731AEBFB6AF209E1B the password "root" (to confirm enter this SQL statment: SELECT PASSWORD('root').

Try to login with the correct password:

$_db_connect = mysql_connect("localhost", "root", "root");
rekire
  • 47,260
  • 30
  • 167
  • 264
1

You are missing the password in the function. Also, the function call is wrong. Do it like this:

$_db_connect = mysql_connect("localhost", "root", "password");

where, password is the password for your root account. It might be different.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • I have tried this, as I say in my original post. Also, my root account has no password. – kingkong Apr 11 '12 at 13:21
  • But the error statement states: `'*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B'` as your root password(obviously encrypted). – hjpotter92 Apr 11 '12 at 13:22
1

pass the password, as the third parameter

$_db_connect = mysql_connect("localhost", "root", "password");
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
1

first param in mysql_connect function is db host and you need to use 3 params - to use password.

so use this syntax:

$db = mysql_connect('localhost', 'mysql_user', 'mysql_password');

xholicka
  • 173
  • 6