Sqlstate hy000 2002 connection refused что это
Перейти к содержимому

Sqlstate hy000 2002 connection refused что это

SQLSTATE[HY000] [2002] Connection refused and SQLSTATE[HY000] [2002] Host is unreachable

I maked docker-compose for elasticsearch and mysql. All container installed "safelly" but when i try to log in to my db with adminer and try it many times i can’t and some error occured: SQLSTATE[HY000] [2002] Connection refused . I don’t know why, i tried to restart my docker and i got SQLSTATE[HY000] [2002] Host is unreachable my db_container keep restarting. Before my db_container keep restarting I already tried to make db manually with docker exec -it db_container_name bash but same still error, i mean can’t connect.

PDOException SQLSTATE [HY000] [2002] Нет такого файла или каталога

Я считаю, что успешно развернул свой (очень простой) сайт на fortrabbit, но как только я подключаюсь к SSH для выполнения некоторых команд (например, php artisan migrate или php artisan db:seed ), я получаю сообщение об ошибке:

В какой-то момент миграция должна была сработать, потому что там есть мои таблицы, но это не объясняет, почему сейчас у меня не работает.

Laravel 4: Change «host» in the app/config/database.php file from «localhost» to «127.0.0.1»

Laravel 5+: Change «DB_HOST» in the .env file from «localhost» to «127.0.0.1»

У меня была точно такая же проблема. Ни одно из вышеперечисленных решений не помогло мне. Я решил проблему, изменив «host» в файле /app/config/database.php с «localhost» на «127.0.0.1».

Не уверен, почему «localhost» не работает по умолчанию, но я нашел этот ответ в аналогичном вопросе, решенном в сообщении symfony2. https://stackoverflow.com/a/9251924/1231563

Обновление: некоторые люди спрашивали, почему это исправление работает, поэтому я немного исследовал эту тему. Кажется, что они используют разные типы подключения, как описано в этом сообщении https://stackoverflow.com/a/9715164/1231563

Здесь возникла проблема, заключающаяся в том, что localhost использует сокет UNIX и не может найти базу данных в стандартном каталоге. Однако «127.0.0.1» использует TCP (протокол управления передачей), что по сути означает, что он работает через «локальный Интернет» на вашем компьютере, что в этом случае намного надежнее, чем сокет UNIX.

Laradock SQLSTATE[HY000] [2002] Connection timed out

You can also use mariadb as the host as we mentioned it the Laradock Setup Snags Post. But only when one container is generated. Read further for when you are using two of them.

Two MariaDB Containers

Using mariadb as host might often work. However, when you are using two containers like me you will need the ip or specific host for the second one:

The example showed the ip I located. You can either use that or the specific host you will find with command mentioned earlier. We had:

earlier. So we picked mariadb_published. So remove laradock_ and _1. As you can see there are two different host names for the two mariadb containers here. If you do not use the specific ip address or specific host name for the second database container you will keep on getting annoying connection refused issues like:

And of course would host be better than ip as host should stick around longer. IP addresses change.

Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *