php 意外异常:SQLSTATE[HY000] [1045] 用户 ****@'localhost' 访问被拒绝(使用密码:YES)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25031874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unexpected Exception: SQLSTATE[HY000] [1045] Access denied for user ****@'localhost' (using password: YES)
提问by segdavids
回答by Basil Nzewure
Sometimes Access denied Exception Error because your mysql credentials are invalid. Secondly, from my experience i observed that this also happens because you did not set password to your database connectivity. eg
有时访问被拒绝异常错误,因为您的 mysql 凭据无效。其次,根据我的经验,我观察到这种情况也会发生,因为您没有为数据库连接设置密码。例如
private $host = "localhost";
private $db_name = "db_dbtest"; // Database name
private $username = "db_user"; // your database username
private $password = "db_password"; // Your password
public $conn;
}
}
Try and set password to your database connectivity. I had such experience and after changing my Collation to utf8_general_ci on the Operations tab, this could not solve my problem. I thought of adding password to my database connection and immediately it connected. You can tesrun this and see if it helps.
尝试为您的数据库连接设置密码。我有这样的经验,在“操作”选项卡上将我的排序规则更改为 utf8_general_ci 后,这无法解决我的问题。我想为我的数据库连接添加密码并立即连接。你可以运行这个,看看它是否有帮助。
回答by surajprogrammez
You're getting Access denied Exception Error because your mysql credentials are invalid.
您收到拒绝访问异常错误,因为您的 mysql 凭据无效。
回答by Avinash Babu
This is due to the wrong sql information provided by you.Changing it to the right one can solve this error .
这是因为你提供的sql信息有误,改成正确的就可以解决这个错误。
回答by Gary Kluth
I was getting this same error code. I'm using phpMyAdmin and added the database with the import of a sql file. The website was using all the same code that had worked before. To fix this error go inside phpMyAdmin and click on the database then operations tab. Change the collation of my database to "ut8_general_ci". Afterwards it was able to verify the username/password access to the database.
我收到了同样的错误代码。我正在使用 phpMyAdmin 并通过导入 sql 文件添加了数据库。该网站使用的所有代码都与以前工作过的代码相同。要修复此错误,请进入 phpMyAdmin 并单击数据库,然后单击操作选项卡。将我的数据库的排序规则更改为“ut8_general_ci”。之后它能够验证对数据库的用户名/密码访问。
Also you might want to make sure you added the user accounts tab the username,password and privileges to access the database.
此外,您可能还想确保在用户帐户选项卡中添加了用户名、密码和访问数据库的权限。
回答by Tom Tom
Well it means the SQL credentials you are using are wrong there is nothing much we can do, you need to use the correct ones or use the root account to change the user's password or rights.
好吧,这意味着您使用的 SQL 凭据是错误的,我们无能为力,您需要使用正确的凭据或使用 root 帐户更改用户的密码或权限。
回答by Erick Shaffer
I know this is an old question, but for me I had to set my password in Sequel Pro to the password that was listed in my .env config file. Hope this helps someone!
我知道这是一个老问题,但对我来说,我必须将 Sequel Pro 中的密码设置为我的 .env 配置文件中列出的密码。希望这可以帮助某人!
回答by Neo101
The first thing you should check is your credentials. I thought i had root
as username and password but when i looked in the file C\xampp\phpMyAdmin\config.inc.php
under
您应该检查的第一件事是您的凭据。我想我已经root
为用户名和密码,但是当我看着在文件中C\xampp\phpMyAdmin\config.inc.php
下
$cfg['Servers'][$i]['password'] = 'WhateverPassword';
I saw that i had a different default password. You should use or change the password that is in that file when trying to connect to your database.
我看到我有一个不同的默认密码。尝试连接到数据库时,您应该使用或更改该文件中的密码。
回答by Felo
You have to specify the port you are using for your MySQL. for me, I was changed the port of MySQL like 3307. example:localhost:3307
您必须指定用于 MySQL 的端口。对我来说,我将 MySQL 的端口更改为 3307。例如:localhost:3307
回答by Design by Adrian
The site you got handed has the login credentials for your colleague's machine/site. Depending on the site, different files need to be changed. Example, Wordpress usually has the settings in a file called wp-config.php
您获得的站点具有您同事的机器/站点的登录凭据。根据站点的不同,需要更改不同的文件。例如,Wordpress 通常在名为wp-config.php的文件中有设置
Until you find this file, maybe you can change your XAMPP user login to match. This article on SO tells how to change SQL login credentials:
在您找到此文件之前,也许您可以更改您的 XAMPP 用户登录以匹配。这篇关于 SO 的文章讲述了如何更改 SQL 登录凭据: