S
S
Sergey Burduzha2021-12-13 10:06:27
MySQL
Sergey Burduzha, 2021-12-13 10:06:27

What is mysql connection error?

Good afternoon.
Mistake

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users`)

mysql settings from .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33062
DB_DATABASE=lv-eliseev
DB_USERNAME=root
DB_PASSWORD=root


mysql settings from docker-compose.yml
mysql:
    image: mysql:5.7
    restart: always
    environment:
      - "MYSQL_ROOT_PASSWORD=root"
    volumes:
      - "./docker/mysql:/var/lib/mysql"
    ports:
      - "33062:3306"


Containers start normally.

Connected to the database through workbench
uvvyA6J.png

Executed php artisan migrateand the tables were created.

docker-compose version 3.1

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-12-13
@serii81

DB_HOST=mysql
DB_PORT=3306

127.0.0.1 inside a container points to the container, not the host. Docker itself creates a network for your containers and they communicate through it, and not through the host.
I ran php artisan migrate and the tables were created.
Stop executing commands on the host - all work must be done in containers, otherwise there is no point in using them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question