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;
echo "<p>".$sql_addr." ".$sql_user." ".$sql_pass." ".$sql_datb."</p>";//DEBUG, shows values are read
echo "<p>Error: Missing values in darkace_config.txt!</p>";
echo "<p>MYSQL Error: ".mysql_error()."</p>";
echo "<p>MYSQL Error selecting database: ".mysql_error()."</p>";
That function is called, and the message I'm returned is:
MYSQL Error: Access denied for user 'root '@'localhost' (using password: YES)
You have 'root[SPACE]' as the user name. Try 'root' without the space?
Something is wrong with your credentials.
Also, please stop using
mysql_* functions as they are now deprecated. Use MySQLi or PDO instead.
Your connection should be like this
$link = mysql_connect('127.0.0.1:3307', 'mysql_user', 'mysql_password');
do not include http, add the port number to like in the example, check user name and password.
If will annoy you but each time you use a mysql_* function you'll get a PDO recommendation. I also recommend PDO, PHP also recomments PDO, you can check PHP Documentation for mysql_connect