Почему получаю SQLSTATE[HY000] [2002] Connection refused, а миграции при этом с БД работают?
Пытаюсь использовать YII локально с докером. Настроил БД. Миграции работают нормально, при этом когда пробую записать или прочитать что-то из таблицы user , к примеру, получаю ошибку :
Менял 127.0.0.1 на localhost.
- Вопрос задан более трёх лет назад
- 12958 просмотров
Средний 2 комментария
- Вконтакте
у меня была такая проблема когда перерёл на винде с докер на докер тулбокс
решил её добавив в docker-compose.yml в настроки mysql


Правильный ответ
Пришлось сделать ДВА(!) конфига . Отдельно для консоли и для остального приложения. Разница в
dsn.
Для консоли
‘dsn’ => ‘mysql:host=127.0.0.1;dbname=project’,
Для остального приложения
‘dsn’ => ‘mysql:host=mysql;dbname=project’,
- Вконтакте


Пытаюсь использовать YII локально с докером.

Привет, столкнулся с той же проблемой, решил твоим методом
Изменил ‘host=127.0.0.1’ на ‘host=mysql’ и ошибка пропала.
Хочу уточнить, ты пишешь:
«Для остального приложения
‘dsn’ => ‘mysql:host=mysql;dbname=project’, «
‘host = mysql’ это потому что контейнер с базой данных так называется (mysql) или если по-другому, то почему?
Laravel: SQLSTATE[HY000] [2002] No such file or directory

If you ever saw this error message in Laravel:
«SQLSTATE[HY000] [2002] No such file or directory»
most likely you have problem with configuration of database connection in your .env file.
To fix it you have to be sure that correct DB_HOST is set in env file and the value of it should be correct. If you are in your local environment try to change from localhost to 127.0.0.1
And after you make this change do not forget to clear the config cache
But in some cases, this could also be wrong. And after you make this change you will get another error:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `sessions` where `id` = .
This error is not really explaining the real problem, but the main problem now is that your DB_HOST IP address is definitely wrong and Laravel actually cannot make connection to this database. In order to fix it double check your DB host IP and port, and update it accordingly.
If you are using XAMPP, open it and check on which IP is working because latest version are using different local IP:

In this case you have to change DB_HOST to
do not forget to run php artisan config:clear to apply the change.
And boom the error is gone!
If you are using some Docker or some other virtual development environment, double check the MySQL IP and port and set it correctly in . env file
ОШИБКА: SQLSTATE [HY000] [2002] Невозможно установить соединение, так как целевой компьютер активно отказал в этом
В процессе отладки кода неожиданно произошла ошибка.
У этого есть ряд ошибок относительно подключения к базе данных.
это код, на который указывает ошибка
В settings.php я все правильно изменил, имя базы данных, пользователя и пароль.
После нескольких часов бессмысленного поиска в Google я изменил порт на пустое значение:
И после этого сайт загрузился правильно.
Перезагрузите ваш wampServer … это должно решить.
и если это не так ..
Реста
Возможно использование разных порт за MySQL чем использовать в вашем коде

Это решило мою проблему.
Просто перезапустите сервер Wamp и запустите php bin / magento cache: чистый
Я получал эту ошибку, пытаясь запустить «php artisan migrate» в Windows с установкой виртуальной коробки / vagrant / homestead.
В документации сказано, что мне нужно было запустить эту команду на виртуальной машине.
Laravel SQLSTATE[HY000] [2002] Connection refused
so I want to deploy my existing Laravel project into my digital ocean VPS I used this tutorial and I uploaded my site successfully.
But here is the problem: I used MySQL and created and ran
and got these errors:
![]()
11 Answers 11
In your .env file, change DB_HOST from 127.0.0.1 to localhost
![]()
It works for MAMP. Set your path to mysql.sock
![]()
In your .env file, change DB_HOST from 127.0.0.1 to localhost
- php artisan cache:clear
- php artisan route:clear
- php artisan config:clear
php artisan view:clear
This worked for me.
![]()
There are a few possibilities why your getting this error.
- database server isn’t started, check if you can still use your phpmyadmin. If you can still use it then nothing is wrong with your database server.
- wrong config; check username, password and server settings in both your .env file and your config/database.php
- no privileges to the server and or database with given credentials Looking at the steps you already took I think it’s the last.
Check to see if this user has access to the database from the remote location. By default the root user has access to the server locally (localhost,127.0.0.1 and ::1).
So check to see if the user has access from either your remote ip or from anywhere.
As you are using digitalocean I would suggest to check if they have a specific configuration to connect to mysql database.