[Access denied for user] error in MySQL. Help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

[Access denied for user] error in MySQL. Help

Post 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 !
User avatar
Technical
Forum Commoner
Posts: 81
Joined: Thu Dec 02, 2010 5:30 am

Re: [Access denied for user] error in MySQL. Help

Post 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.
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

Re: [Access denied for user] error in MySQL. Help

Post 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.
User avatar
Technical
Forum Commoner
Posts: 81
Joined: Thu Dec 02, 2010 5:30 am

Re: [Access denied for user] error in MySQL. Help

Post by Technical »

Try to create another user and check then.
jsk1gcc
Forum Newbie
Posts: 17
Joined: Fri Dec 31, 2010 4:02 pm

Re: [Access denied for user] error in MySQL. Help

Post 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 :)
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

Re: [Access denied for user] error in MySQL. Help

Post 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.
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

Re: [Access denied for user] error in MySQL. Help

Post 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. :D
Post Reply