Domanda

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!

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

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");

pass the password, as the third parameter

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

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');

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top