0

enter image description hereI have tried several option and much confused with setting up mysql connection with Laradock. I changed the mysql version to 5.7 and 5.6 interchangeably and still receiving errors.

Each time I receive

Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = api and table_name = migrations)

Laravel project .env

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3310
DB_DATABASE=api
DB_USERNAME=root
DB_PASSWORD=root

Laradock .env

### MYSQL #################################################

MYSQL_VERSION=latest
MYSQL_DATABASE=api
MYSQL_USER=root
MYSQL_PASSWORD=root
MYSQL_PORT=3310
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d

docker-compose.yml

### MySQL ################################################
    mysql:
      build:
        context: ./mysql
        args:
          - MYSQL_VERSION=${MYSQL_VERSION}
      environment:
        - MYSQL_DATABASE=${MYSQL_DATABASE}
        - MYSQL_USER=${MYSQL_USER}
        - MYSQL_PASSWORD=${MYSQL_PASSWORD}
        - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
        - TZ=${WORKSPACE_TIMEZONE}
      volumes:
        - ${DATA_PATH_HOST}/mysql:/var/lib/mysql
        - ${MYSQL_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d
      ports:
        - "${MYSQL_PORT}:3310"
      networks:
        - backend

I had to change the port from 3306 to 3310 as it was complaining that port was already allocated

enter image description here

enter image description here

Payne
  • 543
  • 2
  • 12
  • 32
  • Ok port 3310? Did you change this from the default of 3306? Or is this a typo – RiggsFolly Apr 23 '19 at 15:54
  • Did you set a password on the `root` user account? Or are you assuming it has one and that it is 'root' – RiggsFolly Apr 23 '19 at 15:55
  • It looks like port 3306 has a MySQL Server on it? Odd you shoudl have 2 in the same docker? – RiggsFolly Apr 23 '19 at 15:56
  • @RiggsFolly yes I changed because when I run docker-compose up - d apache2 mysql phpmyadmin Redis - it displayed an error that port 3306 is already allocated and mysql didn't start up – Payne Apr 23 '19 at 16:02
  • How do I get to know if I have 2 mysql in the same docker and how do I stick to one or remove one. Because I don't know why when I try to up the containers, it displays error of port being allocation and that prompts me to change to port 3310 and I use root as user and root as password to enter on the terminal using docker-compose exec mysql bash – Payne Apr 23 '19 at 16:05
  • It mentions this issue in the laradock documentation. https://laradock.io/documentation/#i-get-mysql-connection-refused – EternalHour Apr 23 '19 at 17:32
  • @EternalHour thanks though I have figured it out – Payne Apr 24 '19 at 12:40

1 Answers1

0

I am able to figure out the problem. To assist anyone who might encounter this ugliness. First, I have MySQL already running on port 3306 which is version 8.0 and trying to run docker-compose up -d mysql, it flags an error, so I decided to change the port to 3310 on docker-compose.yml and Laradock .env and retain 3306 on the project .env. and it works perfectly. I tried to log in to the mysql console to read the port. I changed the DB_HOST to mysql in .env and also on phpmyadmin - on port 8080, server = mysql.

Payne
  • 543
  • 2
  • 12
  • 32