C
C
coderisimo2019-02-07 18:55:46
MySQL
coderisimo, 2019-02-07 18:55:46

Why do I get SQLSTATE[HY000] [2002] Connection refused, while database migrations work?

Trying to use YII locally with docker. Set up the DB. Migrations work fine, but when I try to write or read something from the user table, for example, I get an error:

Database Exception – yii\db\Exception
SQLSTATE[HY000] [2002] Connection refused

Caused by: PDOException
SQLSTATE[HY000] [2002] Connection refused
in /var/www/project.test/vendor/yiisoft/yii2/db/Connection.php at line 687

Changed 127.0.0.1 to localhost.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
coderisimo, 2019-02-07
@coderisimo

Correct answer
I had to make TWO(!) configs . Separately for the console and for the rest of the application. difference in
dsn.
For the console
'dsn' => 'mysql:host=127.0.0.1;dbname=project',
For the rest of the application
'dsn' => 'mysql:host=mysql;dbname=project',

D
Decadal, 2019-02-07
@Decadal

because the console command and the site have different configs and connections. Look for the problem in yii configs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question