用户“root”@localhost 的访问被拒绝 mysql 错误 1045

发布于 2024-10-30 09:55:15 字数 622 浏览 3 评论 0原文

我是 PHP 新手。执行我的应用程序时出现以下错误:

在 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

请告诉我,这里出了什么问题。

I am new to PHP. I get the following error when executing my application:

In phpMyadmin the code is like this

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

As I have taken back up, I have change the above code to

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

Now I am get the following error

Access denied for user 'root'@'localhost' (using password: YES) MySQL Error # :1045

Please let me know, what went wrong here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

风透绣罗衣 2024-11-06 09:55:15

在这个问题上浪费了大部分时间后,事实证明我所要做的就是提供非本地主机主机名。我不知道为什么(允许用户从任何主机连接),但它有效!

root@base:~# 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.

After wasting most of a day on this problem, it turned out that all i had to do was supply the non-localhost hostname. I've no idea why (the user is allowed to connect from Any host), but it works!

root@base:~# mysql -u username -h hostname -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.

And in 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.
不及他 2024-11-06 09:55:15

这里没有人提到(由于某种原因),分配给您的用户的主机可能是错误的。当它显示 root@localhost 时,表示用户 root 的主机为 localhost

在某些服务器上,默认的 root 可能不在 localhost 上。尝试以下操作:

[电子邮件受保护]

root@[你的主机名]

Nobody here has mentioned that (for some reason or another), the host assigned to your user might be wrong. When it says root@localhost it means the user root with the host of localhost.

On some servers, the default root might not be on localhost. Try these:

[email protected]

root@[yourhostname]

伪心 2024-11-06 09:55:15

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

当您的密码与原始密码不匹配时,就会出现此类错误。

Please check the password which you typed here.

These kind of errors come when youre password is not matching with the original password.

魔法唧唧 2024-11-06 09:55:15

确保您是否为 mysql 指定了密码

make sure whether you've assigned a password for mysql

欢烬 2024-11-06 09:55:15

For resetting youre password
please look into this page http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

过期情话 2024-11-06 09:55:15

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

Make sure the password correct (caps lock?) and perhaps use the raw IP address i.e. 127.0.0.1

双手揣兜 2024-11-06 09:55:15

MySQL 服务器及其运行端口可能存在问题。默认值为 3306。如果不起作用,请更改 my.ini 中的端口(或 mysql-ini 文件名),并更改配置中的端口引用。 inc.php 在 phpmyadmin 文件夹中。

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

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

可能会出现,因为 MySQL 服务器未正确运行。

另请查看此帖子以获取有关此问题的更多信息:

无法启动服务器:绑定在 TCP/IP 端口上:没有这样的文件或目录

There can be a problem with MySQL-server and the port on which it is run. Default is 3306. If it doesn't work, change the port in the my.ini (ór whatever the mysql-ini filename is) AND also change the port-reference in the config.inc.php in the phpmyadmin-folder.

So, the error that is explained here (by Gnanendra)

Access denied for user 'root'@'localhost' (using password: YES) MySQL Error # :1045

may be given because MySQL-server is not run correctly.

Also check this post for more information on this issue:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文