用户'root'@'localhost'拒绝访问(使用密码:否)YII

时间:2014-10-09 13:12:00

标签: yii

输入安装数据库配置后

收到错误

错误500 mysql_connect()[function.mysql-connect]:拒绝访问用户&root;' @' localhost' (使用密码:否)

Db配置文件(默认)

(
return array (
  'connectionString' => 'mysql:host=localhost;dbname=sarish',
  'emulatePrepare' => true,
  'username' => 'sarish',
  'password' => 's@r15h',
  'charset' => 'utf8',
);

请帮助我

这是安装控制器代码

<?php

/ ** *权限安装控制器类文件。

* / class InstallController扩展了RController {     / **     * @property RAuthorizer     * /     private $ _authorizer;     / **     * @property RInstaller     * /     private $ _installer;

/**
* Initializes the controller.
*/
public function init()
{
    if( $this->module->install!==true )
        $this->redirect(Yii::app()->homeUrl);

    $this->_authorizer = $this->module->getAuthorizer();
    $this->_installer = $this->module->getInstaller();
    $this->layout = $this->module->layout;
    $this->defaultAction = 'run';

    // Register the scripts.
    $this->module->registerScripts();
}

/**
* @return array action filters
*/
public function filters()
{
    // Use access control when installed.
    return $this->_installer->installed===true ? array('accessControl') : array();
}

/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
    return array(
        array('allow', // Allow superusers to access Rights
            'actions'=>array(
                'confirm',
                'run',
                'error',
                'ready',
            ),
            'users'=>$this->_authorizer->getSuperusers(),
        ),
        array('deny', // Deny all users
            'users'=>array('*'),
        ),
    );
}

/**
* Displays the confirm overwrite page.
*/
public function actionConfirm()
{
    $this->render('confirm');
}

/**
* Installs the module.
* @throws CHttpException if the user is not logged in.
*/
public function actionRun()
{
    // Make sure the user is not a guest.
    if( Yii::app()->user->isGuest===false )
    {
        // Make sure that the module is not already installed.
        if( isset($_GET['confirm'])===true || $this->_installer->installed===false )
        {
            // Run the installer and check for an error.
            if( $this->_installer->run()===RInstaller::ERROR_NONE )
            {
                // Mark the user to have superuser privileges.
                Yii::app()->user->isSuperuser = true;
                $this->redirect(array('install/ready'));
            }

            // Redirect to the error page.
            $this->redirect(array('install/error'));
        }
        // Module is already installed.
        else
        {
            $this->redirect(array('install/confirm'));
        }
    }
    // User is guest, deny access.
    else
    {
        $this->accessDenied(Rights::t('install', 'You must be logged in to install Rights.'));
    }
}

/**
* Displays the install ready page.
*/
public function actionReady()
{
    $this->render('ready');
}

/**
* Displays the install ready page.
*/
public function actionError()
{
    $this->render('error');
}

}

3 个答案:

答案 0 :(得分:0)

尝试这样,

 'db'=>array(
                    'connectionString' => 'mysql:host=localhost;dbname=sarish',
                    'class'=>'CDbConnection',
                    'emulatePrepare' => true,
                    'username' => 'sarish',
                    'password' => 's@r15h',
                    'charset' => 'utf8',
                    'tablePrefix' => '',
            ),

答案 1 :(得分:0)

尝试将localhost更改为您的IP地址127.0.0.1并添加端口号,看看会发生什么。

'connectionString' => 'mysql:host=127.0.0.1;port=3306;dbname=sarish',

答案 2 :(得分:0)

我也遇到了这个问题,这是我的解决方案,我想你的双配置数据库连接,mysql错误:使用密码:NO表示你的密码是空的....所以看看/ Common / config / main-local.php,有一个db连接的预配置,所以你不需要在任何其他配置文件配置数据库连接.....我的英语很糟糕,但我知道你可以理解我..