5

I have problem with connecting to mysql database throw ssh on port 33060, My conf :

return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=myDatabase',
'emulatePrepare' =>true,
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
];

I have open ssh tunel when I try to connect, and i have an error:

SQLSTATE[28000] [1045] Access denied for user 'user'@'localhost' (using password: YES)

What am I doing wrong? Is possible in Yii2 to connect throws ssh?

Thanks for answers!

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
Este
  • 151
  • 1
  • 1
  • 7

3 Answers3

10

I was solve this problem... :

return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=127.0.0.1;port=33060;dbname=myDatabase',
'emulatePrepare' =>true,
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
 ];

It must be 127.0.0.1 not localhost. Thanks for all answers !! :)

Este
  • 151
  • 1
  • 1
  • 7
2

I suspect your main issues would be that you have not specified the port:

return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;port=33060;dbname=myDatabase',
'emulatePrepare' =>true,
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',
];

I assume that you meant to put 33060 as opposed to 3306.

The Humble Rat
  • 4,586
  • 6
  • 39
  • 73
  • I was try with this conf with port, and not working. my tunnel look : ssh -L 33060:localhost:3306 ubuntu@serverAddress.pl – Este Jul 09 '15 at 12:28
0

Sorry for bad english!

Although it is strange this error in localhost, try to make the grant in MySQL:

GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'localhost' IDENTIFIED BY 'your_pass';
jflizandro
  • 622
  • 1
  • 8
  • 16
  • I dont know, i don have this problem in Yii1, in Yii1 all working fine with this configuration... this problem i have only in yii2. – Este Jul 09 '15 at 12:40