Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Can't connect to mysql#1004

Discussion options

Good night!
I'm having a problem that a literally lost my entire day and just can't solve.
What should be the value of DB_HOST of .env to laravel connect successfully to the database?
I already tried:

  • mysql
  • localhost
  • 127.0.0.1
  • host.docker.internal

Nothing seems to work.
I receive errors ofphp_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution orphp_network_getaddresses: getaddrinfo for host.docker.internal failed: Name or service not known orconnection refused

Am I just stupid?
I really don't know what else to do
Here is myyml:

name:CIon:pull_request:branches:[ "main", "develop" ]jobs:laravel-tests:runs-on:ubuntu-22.04services:mysql:image:mysql:8.0env:MYSQL_ROOT_PASSWORD:rootMYSQL_DATABASE:testports:          -3306/tcp# -> here i also tried using 3306:3306options:--health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3steps:    -uses:actions/checkout@v4    -name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.2'extensions:bcmatch, curl, dom, fileinfo, gd, imagick, intl, mbstring, openssl, pdo_mysql, soap, xml, zip# -> here I also tried a set of combination, who knows what might work that this stagecoverage:none    -name:Setup Node.js 22uses:actions/setup-node@v5.0.0with:node-version:'22.x'    -name:Setup FFmpeguses:federicocarboni/setup-ffmpeg@v3.1# I was having problems with other workflows, or with this one, I don't really remember anymore at this point    -name:Remove possible conflicting env filesrun:rm -f .env.example .env.testing .env.testing.example    -name:Copy .envrun:cp .env.ci .env# I also tried removing this and the Cache composer dependencies step    -name:Get composer cache directoryid:composer-cacherun:echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT    -name:Cache composer dependenciesuses:actions/cache@v3with:path:${{ steps.composer-cache.outputs.dir }}# Use composer.json for key, if composer.lock is not committed.# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}key:${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}restore-keys:${{ runner.os }}-composer-    -name:Install Composer Dependenciesrun:composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist    -name:Install python and piprun:sudo apt-get update --allow-releaseinfo-change && sudo apt-get install -y python3 python3-pip    -name:Install pdfmergerun:pip install pdfmerge    -name:Install headless chrome required libsrun:|        sudo apt-get install -y \        libasound2 \        libatk-bridge2.0-0 \        libatk1.0-0 \        libatspi2.0-0 \        libc6 \        libcairo2 \        libcups2 \        libdbus-1-3 \        libdrm2 \        libexpat1 \        libgbm1 \        libglib2.0-0 \        libnspr4 \        libnss3 \        libpango-1.0-0 \        libpangocairo-1.0-0 \        libstdc++6 \        libudev1 \        libuuid1 \        libx11-6 \        libx11-xcb1 \        libxcb-dri3-0 \        libxcb1 \        libxcomposite1 \        libxcursor1 \        libxdamage1 \        libxext6 \        libxfixes3 \        libxi6 \        libxkbcommon0 \        libxrandr2 \        libxrender1 \        libxshmfence1 \        libxss1 \        libxtst6    -name:Install Node dependenciesrun:npm ci    -name:Generate keyrun:php artisan key:generate    -name:Directory Permissionsrun:chmod -R 777 storage bootstrap/cache    -name:Clear Configrun:php artisan config:clear# This step is new, but I just get the errors here now, nothing changes    -name:Run Migrationrun:php artisan migrate -v    -name:Execute Larastanrun:vendor/bin/phpstan analyse          -name:Execute Laravel Pintrun:vendor/bin/pint --test            -name:Execute tests via Pestrun:php artisan test --parallel

My.env.ci that is being copied:

APP_NAME=LaravelAPP_ENV=testingAPP_KEY=APP_DEBUG=trueAPP_TIMEZONE=America/Sao_PauloAPP_URL=http://localhostAPP_LOCALE=pt_BRAPP_FALLBACK_LOCALE=enAPP_FAKER_LOCALE=pt_BRAPP_MAINTENANCE_DRIVER=file# APP_MAINTENANCE_STORE=databaseBCRYPT_ROUNDS=12LOG_CHANNEL=stackLOG_STACK=singleLOG_DEPRECATIONS_CHANNEL=nullLOG_LEVEL=debugDB_CONNECTION=mysqlDB_HOST=127.0.0.1# this was the last attemptDB_PORT=3306DB_DATABASE=testDB_USERNAME=rootDB_PASSWORD=rootSESSION_DRIVER=arraySESSION_LIFETIME=120SESSION_ENCRYPT=falseSESSION_PATH=/SESSION_DOMAIN=nullBROADCAST_CONNECTION=logFILESYSTEM_DISK=localQUEUE_CONNECTION=databaseCACHE_STORE=arrayCACHE_PREFIX=MEMCACHED_HOST=127.0.0.1REDIS_CLIENT=phpredisREDIS_HOST=127.0.0.1REDIS_PASSWORD=nullREDIS_PORT=6379MAIL_MAILER=smtpMAIL_HOST=127.0.0.1MAIL_PORT=1025MAIL_USERNAME=nullMAIL_PASSWORD=nullMAIL_ENCRYPTION=nullMAIL_FROM_ADDRESS="xyz@domain.com"MAIL_FROM_NAME="${APP_NAME}"SMS_ZENVIA_URL=SMS_ZENVIA_TOKEN=SMS_ZENVIA_SENDER_ID=AWS_ACCESS_KEY_ID=AWS_SECRET_ACCESS_KEY=AWS_DEFAULT_REGION=us-east-1AWS_BUCKET=AWS_USE_PATH_STYLE_ENDPOINT=falseVITE_APP_NAME="${APP_NAME}"
You must be logged in to vote

@filipescaglia

First make sure mysql service starts correctly in the second step (Initialize containers)

In your envDB_HOST=127.0.0.1 is correct.

But, when you specify port on a service like this

ports:  -3306/tcp

it maps port 3306 on the service container to a random free port on the host container. Then you cannot hard code a DB_PORT in your env. You have to access it using ${{ job.services.mysql.ports['3306'] }} in this case.

Please try changing these steps

-name:Run Migrationrun:php artisan migrate -venv:DB_PORT:${{ job.services.mysql.ports['3306'] }}

and

-name:Execute tests via Pestrun:php artisan test --parallelenv:DB_PORT:${{ job.services.mysql.por…

Replies: 1 comment 2 replies

Comment options

@filipescaglia

First make sure mysql service starts correctly in the second step (Initialize containers)

In your envDB_HOST=127.0.0.1 is correct.

But, when you specify port on a service like this

ports:  -3306/tcp

it maps port 3306 on the service container to a random free port on the host container. Then you cannot hard code a DB_PORT in your env. You have to access it using ${{ job.services.mysql.ports['3306'] }} in this case.

Please try changing these steps

-name:Run Migrationrun:php artisan migrate -venv:DB_PORT:${{ job.services.mysql.ports['3306'] }}

and

-name:Execute tests via Pestrun:php artisan test --parallelenv:DB_PORT:${{ job.services.mysql.ports['3306'] }}

On a side note, there is a typo in your workflowbcmatch should bebcmath.

You must be logged in to vote
2 replies
@filipescaglia
Comment options

Thanks for the quick response! The changes in the Run Migration and Execute tests via Pest worked!
I just can't believe I wasted an entire day over this. I guess I was unlucky (or just plain stupid) enough not to try using3306:3306 withDB_HOST=127.0.0.1. I think it would have worked, right?

Thanks again.

@shivammathur
Comment options

Yes that would also work.

Answer selected byfilipescaglia
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
2 participants
@filipescaglia@shivammathur

[8]ページ先頭

©2009-2025 Movatter.jp