尝试连接到数据库时出现异常错误 [英] Bizarre error when trying to connect to database

查看:136
本文介绍了尝试连接到数据库时出现异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最后一天左右,我无法通过PHP连接到数据库。这是我的代码连接到数据库看起来像



$ con = mysqli_connect(localhost,root,password );
这里是奇怪的错误。


PHP警告:mysqli_connect HY000 / 1045):第2行的用户'user'@'localhost'拒绝访问(使用密码:YES)


我通常会得到这个错误,如果凭据不正确,但我使用GUI和测试与确切凭证的连接,因此意味着,这不是问题。我刚开始随机得到这个错误,并重新启动我的电脑,重新安装MySQL,重新配置服务器我也试过 127.0.0.1 ,而不是 localhost 我在 localhost 所以我几乎完全控制任何东西,我没有弄乱任何导致这个问题。有任何想法吗?

解决方案

由于某种原因,该函数尝试使用user用户而不是root

您可以通过添加错误链接进一步调试:



$ con = mysqli_connect(myhost ,myuser,mypassw,mybd)或die(Error。mysqli_error($ con));


Over the last day or so I'm not able to connect to a database through PHP. Here's what my code connecting to the database looks like

$con = mysqli_connect("localhost","root","password","database"); And here's the strange error.

PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES) in - on line 2

I'd usually get that error if the credentials are incorrect, but I used a GUI and tested the connection with the exact credentials, where therefore means that, that is not the issue. I just started randomly getting this error and have restarted my computer, reinstalled MySQL, and reconfigure the server I've also tried 127.0.0.1 instead of localhost I'm on localhost so I have full control on pretty much anything and I didn't mess with anything causing this issue. Any ideas?

解决方案

For some reason the function is trying to connect using the "user" user instead of "root".

You can debug further by adding the error link:

$con= mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($con));

这篇关于尝试连接到数据库时出现异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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