Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

laravel and docker error SQLSTATE [HY000] [2002] Connection refused #2142

Closed
tomi0001 opened this issue May 21, 2019 · 11 comments
Closed

laravel and docker error SQLSTATE [HY000] [2002] Connection refused #2142

tomi0001 opened this issue May 21, 2019 · 11 comments
Labels

Comments

@tomi0001
Copy link

tomi0001 commented May 21, 2019

Info:

  • Linux
  • Debian 9.5

Issue:

I have a problem I want to put a project in a docker laravelu and this project I do not want to move after this message SQLSTATE [HY000] [2002] Connection refused I've tried everything mysql port change before it was 3307 now it's 3306?


Expected behavior:


Reproduce:


Mój env

Relevant Code:

APP_KEY=
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=saskakepa.test
APP_PROTOCOL=http

VRKANSAGARA_COMPRESS_ENVIRONMENT='${APP_ENV}'

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sas
DB_USERNAME=tomi
DB_PASSWORD=a1234

SK_DB_DATABASE=
SK_DB_HOST=
SK_DB_USERNAME=
SK_DB_PASSWORD=
SK_DB_PORT=3306

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

AWS_KEY=
AWS_SECRET=
AWS_BUCKET=ecityapplication
AWS_REGION=eu-central-1

RECAPTCHA_PUBLIC_KEY=
RECAPTCHA_PRIVATE_KEY=

INSTAGRAM_USER=
INSTAGRAM_PASSWORD=

AIRLY_TOKEN=

FACEBOOK_APP_ID=
FACEBOOK_SECRET=

GOOGLE_TAG_MANAGER=
GOOGLE_MAPS_JS_KEY=

LINKEDIN_KEY=
LINKEDIN_SECRET=
LINKEDIN_REDIRECT_URI=


TWITTER_URL=https://api.twitter.com/1.1/statuses/update.json
TWITTER_OAUTH_ACCCESS_TOKEN=
TWITTER_OAUTH_ACCCESS_TOKEN_SECRET=
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=

# incoming emails email address
EMAIL_TO_NOTIFICATIONS=

ROLLBAR_TOKEN=
ROLLBAR_LEVEL=debug
ROLLBAR_ENABLED=true

ZOMATO_KEY=

CONVERTAPI_TOKEN=
AWS_BUCKET_BACKUP=

BOTMAN_FB_TOKEN=
BOTMAN_FB_SECRET=
BOTMAN_FB_VERIFICATION_TOKEN=

docker.yam

version: '2'
services:
  application_nginx:
    container_name: saska_application_nginx
    build: ./build/nginx/.
    ports:
     - "8082:80"
    networks:
     - appnet
    volumes:
     - ./:/var/www/html
    environment:
      VIRTUAL_HOST: saskakepa.test
  application:
    container_name: saska_application
    build: ./.
    networks:
     - appnet
    volumes:
     - ./:/var/www/html
     - ./build/php/zdev._ini:/usr/local/etc/php/conf.d/zdev.ini
    environment:
      APP_ENV: local
  mysql:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: mysql
      MYSQL_DATABASE: sas
      MYSQL_USER: tomi
      MYSQL_PASSWORD: a1234
    volumes:
     - data:/var/lib/mysql
    networks:
     - appnet
    ports:
     - "3307:3306"
    expose:
     - "3306"
networks:
  appnet:
    driver: "bridge"
volumes:
  data:
    driver: "local"
@bestlong
Copy link
Member

DB_HOST=mysql

@tomi0001
Copy link
Author

I made and now is error

SQLSTATE[HY000] [1045] Access denied for user 'tomi'@'172.18.0.4' (using password: YES)

@mlapan
Copy link

mlapan commented May 24, 2019

did you create that user on the mysql DB?

@tomi0001
Copy link
Author

Yes.

@qzoke
Copy link

qzoke commented May 26, 2019

@tomi0001 This error has nothing to do with laradock.
One of the following is cause of this error

  1. Your user has no privilege to database in question.
    Check if user 'tomi' has GRANT ALL ACCESS to the database you are using and if that database exists. Use mysql terminal for checking the same.

  2. You are running query even before docker can load all necessary services, like mysql
    Please start docker and wait for 2 minutes and try if everything working this time

Let us know if this solves your Issue

@tomi0001
Copy link
Author

@qzoke
How do I set permissions for all hosts other than 127.0.0.1 for user tomi?

@qzoke
Copy link

qzoke commented May 27, 2019

@tomi0001 I don't think this is a right thread for you to add bugs that can be easily solved. If you are using docker, I am assuming you know basic SQL or at least google SQL query to grant database access to the user.

Please use StackOverflow, not GitHub Issues.

@FARUK-YILDIRIM
Copy link

I have solved this problem this way.

1- Docker -> Preferences ->Reset -> Reset to factory defaults (Removes all settings and data. Just like new.)
2- Docker update. (There was a new update)
3- I made mysql version 8 of laradock env file. Note: I use mysql version 8.0 because did not work in another version

MYSQL_VERSION=8.0
MYSQL_DATABASE=default
MYSQL_USER=default
MYSQL_PASSWORD=secret
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d

4- I switched to the working environment.
docker-compose exec workspace bash
5- php artisan migrate

Worked for me :)

@pabloleone
Copy link

There's no way to connect to the MYSQL container from outside. I've tried the workspace command

docker-compose run workspace php artisan migrate

and trying to access directly

docker-compose run mysql mysql -udefault -psecret -h127.0.0.1 default

I can access from into the mysql container.

I've created a user and grant all access to all DB from localhost and still not being able to connect from outside. It always says connection refused.

I'm using MYSQL 5.7!

I've tried with version 8 but I hi another issue with the client hash that hasn't been solved yet!

Anyone with a good idea?

Thank you!

@stale
Copy link

stale bot commented Feb 17, 2020

Hi 👋 this issue has been automatically marked as stale 📌 because it has not had recent activity 😴. It will be closed if no further activity occurs. Thank you for your contributions ❤️.

@stale stale bot added the Stale label Feb 17, 2020
@stale
Copy link

stale bot commented Mar 9, 2020

Hi again 👋 we would like to inform you that this issue has been automatically closed 🔒 because it had not recent activity during the stale period. We really really appreciate your contributions, and looking forward for more in the future 🎈.

@stale stale bot closed this as completed Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants