2011-04-05 152 views
4

我是PHP新手。在执行我的应用程序时,我得到了以下错误:访问被拒绝用户'root'@ localhost mysql错误1045

在phpMyAdmin的代码是这样的

$cfg['Servers'][$i]['auth_type'] = 'config'; 
$cfg['Servers'][$i]['user'] = 'root'; 
$cfg['Servers'][$i]['password'] = ''; 
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true; 

正如我已经收回了,我上面的代码更改为

$cfg['Servers'][$i]['auth_type'] = 'config'; 
$cfg['Servers'][$i]['user'] = 'root'; 
$cfg['Servers'][$i]['password'] = 'Pass123'; 
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true; 

现在我得到以下错误

访问被拒绝用户'root'@'localhost'(使用密码:YES)MySQL错误#:1045

请让我知道,出了什么错在这里。

+0

你有没有确认是否1)你有正确的用户名/密码? 2)你的域名是否可以实际连接到mysql服务器(使用phpMyAdmin来验证) – JohnP 2011-04-05 04:43:33

+0

你有没有做过一点搜索,请参阅http://stackoverflow.com/questions/2912761/beginner-mysql-error-access-denied http ://stackoverflow.com/questions/2540794/unable-to-access-mysql-from-myphpadmin-after-setting-root-password-in-easyphpwam http://stackoverflow.com/questions/3532868/mysql-error- 1045-access-denied – gideon 2011-04-05 04:45:07

+0

分享一些代码....所以我们可以帮忙,似乎你没有通过正确的密码到函数mysql_connect – Necronet 2011-04-05 04:46:05

回答

0

请检查您在此输入的密码。

这样的错误来时候你的密码是不与原来的密码匹配。

+0

我怎么能现在重置密码 – Gnanendra 2011-04-05 05:31:45

0

确保您是否已经分配给mysql的

+0

不,我没有给它分配任何密码......我做了上面我只提到的 – Gnanendra 2011-04-05 05:31:05

+0

,那么不要在这里指定密码'$ cfg ['Servers'] [$ i] ['password'] ='Pass123''删除'pass123' – Mujahid 2011-04-05 09:19:00

0

可以有与MySQL服务器的问题,并在其上的端口跑。默认值是3306。如果它不工作,改变端口的my.ini(或任何使用mysql-INI文件名),改变在phpMyAdmin的文件夹中config.inc.php端口参考。

所以,这(通过Gnanendra)这里解释错误

访问被拒绝的用户 '根' @ 'localhost' 的(使用密码:YES)MySQL错误#:1045

可能会给出,因为MySQL服务器没有正确运行。

还要检查这个职位对这个问题的详细信息:

Can't start server: Bind on TCP/IP port: No such file or directory

0

确认密码是否正确(大写锁定?)也许是使用原始IP地址127.0.0.1即

1

没人这里提到(出于某种原因),分配给用户的主机可能是错误的。当它说[email protected]这意味着用户root主机localhost

在一些服务器上,默认root可能不是在localhost。试试这些:

[email protected]

[email protected][yourhostname]

+0

这解决了我的问题! – 2013-04-10 09:16:42

+0

请将此答案标记为已接受,如果它解决了所有问题。 – Alfo 2013-04-10 14:56:23

+0

我不行。我没有问这个问题...... – 2013-04-11 23:35:24

2

最浪费了一天的这个问题后,事实证明,我所要做的就是提供非本地主机的主机名。我不知道为什么(用户可以从任何主机连接),但它的工作原理!

[email protected]:~# mysql -u username -h hostname -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g. 

而在PHP:

Test 1807: 
<?php 
$username = "username"; 
$password = "password"; 
$hostname = "actualhostnamenotlocalhost"; 

$con = mysqli_connect($hostname, $username, $password); 

// Check connection 
if (mysqli_connect_errno($con)){ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

mysqli_close($con);  

?> 
OK. 
相关问题