php PDOException: SQLSTATE[28000] [1045] 用户访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22322340/
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
PDOException: SQLSTATE[28000] [1045] Access denied for user
提问by swap-nil
I was having the same error message when starting an existing project on another computer. As the repository wasn't online already, I had to copy the whole D7 folder from PC1 to PC2, and import the database in phpMyAdmin. I've got this error as result when accessing my (localhost) homepage.
在另一台计算机上启动现有项目时,我遇到了相同的错误消息。由于存储库尚未在线,我不得不将整个 D7 文件夹从 PC1 复制到 PC2,并在 phpMyAdmin 中导入数据库。访问我的(本地主机)主页时出现此错误。
"PDOException: SQLSTATE[28000] [1045] Access denied for user '***'@'apache2-**.dreamhost.com' (using password: YES) in lock_may_be_available() (line 165 of /home/**/**.INFO/includes/lock.inc)."
回答by Vasiliy Vanchuk
Check, that user defined at your scripts created and have permissions to using database ( on copying database you transfer data, not users and permissions)
检查,在您的脚本中定义的用户创建并有权使用数据库(在复制数据库时您传输数据,而不是用户和权限)
PhpMyAdmin allow do this
PhpMyAdmin 允许这样做
Or simple create new user ( look username and password at your configuration script )
或者简单地创建新用户(在您的配置脚本中查看用户名和密码)
回答by swap-nil
I have solved my question its for help i am writing the answer for having same problem,
我已经解决了我的问题以寻求帮助我正在为遇到同样的问题写答案,
firstly go to your /sites/default/settings.php and simply change these files in your new site which you want to run as well as old,
首先转到您的 /sites/default/settings.php 并简单地更改您要运行的新站点中的这些文件以及旧站点,
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'databasenameofyournewdatabase',
'username' => 'usernameonthatserver',
'password' => 'passwordonthatserver',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
回答by philips
This error appears to me when I add my user to the MySQL Workbench and use "remember my password".
当我将我的用户添加到 MySQL Workbench 并使用“记住我的密码”时,我会看到这个错误。
If this is your case, try editing settings.phpin $databasesand removing the password of your user, because it is already "remembered".
如果您遇到这种情况,请尝试编辑settings.php在$databases和拆卸用户的密码,因为它已经被“记住”。

