Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nafeeur10's avatar

SQLSTATE[HY000] [2002] Connection refused laravel docker

I am trying to migrate my database. Giving this error.

I got in docker this error:

Error starting userland proxy: listen tcp4 0.0.0.0:3306: bind: address already in use

Then I kill this port:

sudo kill `sudo lsof -t -i:3306``

Now, I am using this port to connect my db:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=inventory
DB_USERNAME=root
DB_PASSWORD=root

docker-compose.yml

database:
    image: mysql:5.7.22
    restart: always
    container_name: mysql-database
    command: mysqld --sql_mode=""
    volumes:
      - "./data/db:/var/lib/mysql"
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: root
      MYSQL_PASSWORD: 123456
      MYSQL_ROOT_PASSWORD: root
    ports:
      - 3306:3306
    networks:
      - development_network

Now, how can I solve this problem?

0 likes
6 replies
Sergiu17's avatar

Try to stop local installed mysql

service mysqld stop
// or
service mysql stop

then

sail down
sail up -d
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

oh, sorry

docker-compose stop
docker-compose up -d

// or

docker-compose restart

restart the containers

2 likes
siangboon's avatar

the error said there is a service (mysql) already using this port 3306, if you are not using it then just stop the service temporary or uninstall it, but if you want to use both at the same time then just change either service to use other port number...

Please or to participate in this conversation.