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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

flyclassic22

Technical User
Oct 1, 2002
54
SG
i'm totally new to php and mysql, i've use ASP before though with microsoft access db, odbc connection. I'ved tried installing the php windows installer to my winxp(with IIS) and then mysql server 4.3.1 everything installed
saw an example from the web, and decided to try out..
myphpfile.php
<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
printf("First Name: %s<br>\n", mysql_result($result,0,"first"));
printf("Last Name: %s<br>\n", mysql_result($result,0,"last"));
printf("Address: %s<br>\n", mysql_result($result,0,"address"));
printf("Position: %s<br>\n", mysql_result($result,0,"position"));
?>
</body>
</html>
in mysql, i've created the following database
mydb
CREATE TABLE employees ( id tinyint(4) NOT NULL AUTO_INCREMENT, first varchar(20), last varchar(20), address varchar(255), position varchar(50), PRIMARY KEY (id), UNIQUE id (id));INSERT INTO employees VALUES (1,'Bob','Smith','128 Here St, Cityname','Marketing Manager');
INSERT INTO employees VALUES (2,'John','Roberts','45 There St , Townville','Telephonist');
INSERT INTO employees VALUES (3,'Brad','Johnson','1/34 Nowhere Blvd, Snowston','Doorman');


however when i tried accessing my i've got the following message.
Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) .
It seems like it cannot access mysql server, i don't know how, stuck from there, i've trying to read the password hashing in the documentation, but not quite understand.
Perhaps anyone can help?
 
It sounds like you need a password for root. Do you remember setting the root password when you installed MySQL?

Try connecting with:

Code:
$db = mysql_connect("localhost", "root","password");

substituting your password for "password" above.
 
thanks alot pal!, i've tried with my password and it returns
Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\wilsons\Projects Websites & SchoolTime Files\Php&MySQL Tutorial\tut1test_part2_mysql.php on line 13

..
??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top