Page 1 of 1
[Access denied for user] error in MySQL. Help
Posted: Fri Dec 31, 2010 11:13 am
by phazorRise
Error accessing MySQL database.
Code using for connection is -
Code: Select all
<?php
$db_name="global_db";// Database name
$conn=mysql_connect("localhost","root","phazorRise") or die("I Couldn't connect");
$db=mysql_select_db($db_name,$conn) or die("I Couldn't select your database");
?>
Error message I'm getting:
Warning: Access denied for user 'root@localhost'(Using password YES) in c:\apache\htdocs\db.php on line 3
Warning:MySQL Connection Failes:Access ddenied for user: 'root@localhost'(Using password YES) in c:\apache\htdocs\db.php on line 3
Couldn't make connection
It was working well. I did some modifications in my form and submitted, and I get surprised by this ERROR.
Please Help !
Re: [Access denied for user] error in MySQL. Help
Posted: Fri Dec 31, 2010 11:17 am
by Technical
phazorRise wrote:Warning: Access denied for user 'root@localhost'(Using password YES) in c:\apache\htdocs\db.php on line 3
Warning:MySQL Connection Failes:Access ddenied for user: 'root@localhost'(Using password YES) in c:\apache\htdocs\db.php on line 3
Couldn't make connection
Well, it's pretty obvious. Either user is gone or password is incorrect.
Re: [Access denied for user] error in MySQL. Help
Posted: Fri Dec 31, 2010 11:21 am
by phazorRise
Technical wrote:phazorRise wrote:Warning: Access denied for user 'root@localhost'(Using password YES) in c:\apache\htdocs\db.php on line 3
Warning:MySQL Connection Failes:Access ddenied for user: 'root@localhost'(Using password YES) in c:\apache\htdocs\db.php on line 3
Couldn't make connection
Well, it's pretty obvious. Either user is gone or password is incorrect.
I'm aware of this but I know my both user and passwords. I tried it from command prompt and it's accepting it. But through code, it's showing that error.
Re: [Access denied for user] error in MySQL. Help
Posted: Fri Dec 31, 2010 1:13 pm
by Technical
Try to create another user and check then.
Re: [Access denied for user] error in MySQL. Help
Posted: Fri Dec 31, 2010 4:41 pm
by jsk1gcc
i had this error earlier on today, turned out my password and user name were the wrong way around within the connect statement
when i looked into it i found another post that suggested this.
Code: Select all
//CONNECT TO DATABASE
$username = '*******';
$password = '*******';
$host = '*********';
$dbname = '********';
$connection = mysql_connect($host, $username, $password);
if (!$connection) {
die ('connection failed' . mysql_error());
}
echo 'Connected sucessfully';
//////edit out echo once done/////
$select = mysql_select_db($dbname);
if (!$select) {
die('select not working' . mysql_error());
}
echo 'selected sucessfully';
//////edit out echo once done////
it's longer than what you've got but this way you can test each statement to see what works and what does not.
hope you get it fixed

Re: [Access denied for user] error in MySQL. Help
Posted: Fri Dec 31, 2010 11:39 pm
by phazorRise
Technical wrote:Try to create another user and check then.
I fixed the problem. I just restarted both Apache and MySQL.
Then dropped old DB and again created new DB with desired table.
Now I can connect to MySQL. Thank you for suggestions.
Re: [Access denied for user] error in MySQL. Help
Posted: Sat Jan 01, 2011 12:09 am
by phazorRise
jsk1gcc wrote:i had this error earlier on today, turned out my password and user name were the wrong way around within the connect statement
when i looked into it i found another post that suggested this.
Code: Select all
//CONNECT TO DATABASE
$username = '*******';
$password = '*******';
$host = '*********';
$dbname = '********';
$connection = mysql_connect($host, $username, $password);
if (!$connection) {
die ('connection failed' . mysql_error());
}
echo 'Connected sucessfully';
//////edit out echo once done/////
$select = mysql_select_db($dbname);
if (!$select) {
die('select not working' . mysql_error());
}
echo 'selected sucessfully';
//////edit out echo once done////
it's longer than what you've got but this way you can test each statement to see what works and what does not.
hope you get it fixed

thnax for the code but i have fixed error already. i just restarted both MySQL and Apache Server.
