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

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: )

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?