PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 11, 2022

[FIXED] PHP - MySQL access denied error - Works in other programs

 February 11, 2022     lamp, linux, mysql, php     No comments   

Issue

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

Yes, this error is all too common, and I have spent much time researching it. However nothing solved the problem.

I get this error when attempting the first connect in one of my PHP scripts I'm developing. If it helps to know, I'm running Linux Mint with the LAMP configuration detailed at http://community.linuxmint.com/tutorial/view/486 installed.

The thing is, any other application works with connecting. Both logging into PhpMyAdmin as root or mysql client on the console as root work perfectly. The MySQL site itself says that it's likely a problem with my code, but I have yet to figure that out... I am kinda new to this stuff so please forgive me if it's a very nooby mistake.

I'm using an external function on a different page (imported with require_once). Is this a bad practice? Regardless, here it is:

global $sql_conn, $sql_addr, $sql_user, $sql_pass, $sql_datb;

$config=app_readconfig();
echo "<p>".$sql_addr." ".$sql_user." ".$sql_pass." ".$sql_datb."</p>";//DEBUG, shows values are read
if($config==FALSE)
{
    echo "<p>Error: Missing values in darkace_config.txt!</p>";
    return FALSE;
}
$sql_conn=mysql_connect($sql_addr,$sql_user,$sql_pass);
if(!$sql_conn)
{
    echo "<p>MYSQL Error: ".mysql_error()."</p>";
    return FALSE;
}

if(!mysql_select_db($sql_datb,$sql_conn))
{
    echo "<p>MYSQL Error selecting database: ".mysql_error()."</p>";
    return FALSE;
}
return TRUE;

That function is called, and the message I'm returned is: MYSQL Error: Access denied for user 'root '@'localhost' (using password: YES)


Solution

You have 'root[SPACE]' as the user name. Try 'root' without the space?



Answered By - Robbie
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing