0

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

zzlalani
  • 22,960
  • 16
  • 44
  • 73
Ionut Flavius Pogacian
  • 4,750
  • 14
  • 58
  • 100

2 Answers2

3

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

Community
  • 1
  • 1
Daniel Vaquero
  • 1,315
  • 1
  • 8
  • 13
  • what do you mean with %root access? – Ionut Flavius Pogacian Oct 16 '13 at 06:31
  • root@% means root can access from any host. I think by default root can only access from localhost. Of course that then means that any hacker can attempt to access your server with root access from any client that can get to it. Better not to use root, and to restrict the user that you are using to the server that your Yii application runs on. – jmarkmurphy Oct 16 '13 at 15:28
2

It's a problem of server accessebily, not user access. Check number of port of mysql server (must be 3306, if not - use mysql:host=192.168.0.2;port=<your port>;dbname=mydb) and try to ping 192.168.0.2 (or maybe can run this nmap -p 3306 -sT 192.168.0.2, it from here) from the where yii placed

CreatoR
  • 1,654
  • 10
  • 14