PHP-MySQL访问被拒绝错误-在其他程序中有效 [英] PHP - MySQL access denied error - Works in other programs

查看:85
本文介绍了PHP-MySQL访问被拒绝错误-在其他程序中有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

当我正在开发的一个PHP脚本中尝试进行首次连接时,出现此错误.如果有帮助的话,我正在运行Linux Mint,其LAMP配置在 http://community中进行了详细介绍.linuxmint.com/tutorial/view/486 已安装.

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.

问题是,任何其他应用程序都可以与连接一起使用.以root用户身份登录PhpMyAdmin或以root用户身份在控制台上运行mysql客户端都可以正常工作. MySQL站点本身说这可能是我的代码有问题,但是我还没有弄清楚……我对这个东西有点陌生,所以如果这是一个非常不合理的错误,请原谅我.

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.

我在另一个页面上使用了外部函数(随require_once一起导入).这是不好的做法吗?无论如何,这里是:

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;

该函数被调用,返回的消息是: MYSQL错误:用户'root'@'localhost'的访问被拒绝(使用密码:是)

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

推荐答案

您具有"root [SPACE]"作为用户名.尝试在没有空格的情况下"root"吗?

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

这篇关于PHP-MySQL访问被拒绝错误-在其他程序中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆