使用 yii 连接 mysql 时访问被拒绝
当尝试使用 Yii 连接到我的数据库时,我收到此错误,
我确信密码和权限是正确的。我如何找到这里的问题?
我正在运行 MAMP 和最新的 Yii。
CDbException
CDbConnection failed to open the DB connection: SQLSTATE[28000] [1045] Access denied for user 'yii'@'localhost' (using password: YES)
/Users/user/Dropbox/localhost/yii/framework/gii/generators/model/ModelCode.php(54)
42 ));
43 }
44
45 public function requiredTemplates()
46 {
47 return array(
48 'model.php',
49 );
50 }
51
52 public function init()
53 {
54 if(Yii::app()->db===null)
55 throw new CHttpException(500,'An active "db" connection is required to run this generator.');
56 $this->tablePrefix=Yii::app()->db->tablePrefix;
57 parent::init();
58 }
59
60 public function prepare()
61 {
62 if(($pos=strrpos($this->tableName,'.'))!==false)
63 {
64 $schema=substr($this->tableName,0,$pos);
65 $tableName=substr($this->tableName,$pos+1);
66 }
I get this error when trying to connect to my db with Yii
I am sure the password and permissions are correct. How do I track down the problem here?
I am running MAMP and the latest Yii.
CDbException
CDbConnection failed to open the DB connection: SQLSTATE[28000] [1045] Access denied for user 'yii'@'localhost' (using password: YES)
/Users/user/Dropbox/localhost/yii/framework/gii/generators/model/ModelCode.php(54)
42 ));
43 }
44
45 public function requiredTemplates()
46 {
47 return array(
48 'model.php',
49 );
50 }
51
52 public function init()
53 {
54 if(Yii::app()->db===null)
55 throw new CHttpException(500,'An active "db" connection is required to run this generator.');
56 $this->tablePrefix=Yii::app()->db->tablePrefix;
57 parent::init();
58 }
59
60 public function prepare()
61 {
62 if(($pos=strrpos($this->tableName,'.'))!==false)
63 {
64 $schema=substr($this->tableName,0,$pos);
65 $tableName=substr($this->tableName,$pos+1);
66 }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在文件 /protected/config/main.php 中查找“组件”块并根据需要进行更新:(
将 UC 值更改为您的设置)。并阅读这些页面。
In the file /protected/config/main.php look for the "components" block and update as needed:
(change UC vals to your settings). And read these pages.
确保您已在正确的配置文件(在
/config
中)中输入数据库信息。据推测,Gii 使用的是main.php
配置文件,因此请确保您没有在console.php
或test.php 意外地出现在
main.php
上。Make sure you have entered your database info in the correct configuration file (in
/config
). Presumably Gii is using themain.php
config file, so make sure you didn't set up the DB credentials inconsole.php
ortest.php
by accident instead onmain.php
.如果您确定提供的凭据正确,则
yii
用户不得具有从localhost
连接的权限。 MySQL 身份验证是通过用户名、密码和主机完成的,因此读起来就像其中之一不正确。If you are sure that the supplied credentials are correct, then the
yii
user must not have permission to connect fromlocalhost
. MySQL authentication is done by username, password, and host, so it reads like one of those is incorrect.如果您在本地计算机上使用 mamp,请确保在 main.php 文件中将您的用户名设置为“root”,并将密码设置为“root”。默认情况下将密码设置为空,这将导致上述错误。
If you are using mamp on a local machine make sure your username is set to 'root' and the password is set to 'root' in the main.php file. The default is to set password to null and this will cause the error above.
确保您更改了 console.php 中的凭据( yiic 不会查找 main.php ,尽管它重复了相同的内容)
make sure you change the credentials in console.php ( yiic will not look for main.php , though it has the same thins repeated )
这里我有工作代码:
OS Ubuntu:
为我工作:-)
Here I have working code:
OS Ubuntu:
Working for me :-)
我遇到了这个问题。
解决方法:
打开文件
yii/config/db.php
并添加 phpmyadmin 的数据(密码和名称)。
I had this problem.
Solved it by:
Open file
yii/config/db.php
and add your data for phpmyadmin (password&name).