dopcpc9207
2013-10-16 06:25
浏览 82
已采纳

Yii:如何远程连接到数据库?

I am trying to connect to a db remotely using the Yii framework

Is there any specific setting because i can't connect to the db.

'db' => array(
    'class' => 'PortalDbConnection',
    'connectionString' => 'mysql:host=192.168.0.2;dbname=mydb',
    'username' => 'root',
    'password' => '',
    'tablePrefix' => '',
    'emulatePrepare' => true,
    'enableParamLogging' => true,
    'enableProfiling' => true,
    'charset' => 'utf8',
),

Error

2013/10/16 09:14:22 [error] [exception.CDbException] SQLSTATE[HY000]
[2003] Can't connect to MySQL server on 'mysql5.ms.domain.net' (13)
2013/10/16 09:14:22 [info] [application] User: Guest (ID: )

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用 Yii框架远程连接数据库

是否有任何特定设置,因为我无法连接到数据库。

 'db'=>  array(
'class'=>'PortalDbConnection',
'connectionString'=>'mysql:host = 192.168.0.2; dbname = mydb',
'username'=>'root',
  'password'=>'',
'tablePrefix'=>'',
'emulatePrepare'=> true,
'enableParamLogging'=> true,
'enableProfiling'=> true,  
'charset'=>'utf8',
),
   
 
 

错误 < blockquote>

2013/10/16 09:14:22 [error] [exception.CDbException] SQLSTATE [HY000]
[2003]无法连接到'mysql5.ms上的MySQL服务器。 domain.net'(13)
2013/10/16 09:14:22 [info] [application]用户:Guest(ID:)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 「已注销」 2013-10-16 06:30
    已采纳

    This code is valid for me:

    'db'=>array( 
            'connectionString' => 'mysql:host=192.168.1.96;dbname=dbname',
            'emulatePrepare' => true,
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
            'enableProfiling'=>true,
            'enableParamLogging' => true,
        ),
    

    Do you have configurated on the DB server the %root access, from remote?

    Edited:

    For configure remote access:

    There's two steps in that process:

    a) Grant privileges. As root user execute:

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
    

    b) bind to all addresses:

    The easiest way is to comment out the line in your my.cnf file:

    #bind-address = 127.0.0.1 
    

    and restart mysql

    service mysql restart
    

    @hovanessyan solution: MySQL root access from all hosts

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题