title: Laravel Github Actions CI/CD , SQLSTATE[HY000] [2002] Connection refused (SQL: create table `migrations`
body: <p>I want to run my unit tests through my yml file, but they fail because they must be run on Mysql</p>
  <p>I think something is missing.</p>
  <p>here is yaml file:</p>
  <pre><code>steps:
      - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
        with:
          php-version: '7.4|8.0'
      - uses: actions/checkout@v2
      - name: Copy .env
        run: php -r &quot;file_exists('.env') || copy('.env.example', '.env');&quot;
      - name: Install Dependencies
        run: composer install --no-progress --prefer-dist --optimize-autoloader
      - name: Generate key
        run: php artisan key:generate
  
      - name: Directory Permissions
        run: chmod -R 777 storage bootstrap/cache
  
      - name: Optimize Project
        run: php artisan optimize:clear
  
      - name: Execute tests (Unit and Feature tests) via PHPUnit
        env:
          DB_CONNECTION: mysql
          DB_HOST: 127.0.0.1
          DB_PORT: 3306
          DB_DATABASE: database_name
          DB_USERNAME: root
          DB_PASSWORD:
        run: |
          php artisan migrate
          php artisan test
  </code></pre>
  <p>and here is phpunit.xml file:</p>
  <pre><code>&lt;server name=&quot;APP_ENV&quot; value=&quot;testing&quot;/&gt;
          &lt;server name=&quot;BCRYPT_ROUNDS&quot; value=&quot;4&quot;/&gt;
          &lt;server name=&quot;CACHE_DRIVER&quot; value=&quot;array&quot;/&gt;
          &lt;!-- &lt;server name=&quot;DB_CONNECTION&quot; value=&quot;sqlite&quot;/&gt; --&gt;
          &lt;!-- &lt;server name=&quot;DB_DATABASE&quot; value=&quot;:memory:&quot;/&gt; --&gt;
          &lt;server name=&quot;MAIL_MAILER&quot; value=&quot;array&quot;/&gt;
          &lt;server name=&quot;QUEUE_CONNECTION&quot; value=&quot;sync&quot;/&gt;
          &lt;server name=&quot;SESSION_DRIVER&quot; value=&quot;array&quot;/&gt;
          &lt;server name=&quot;TELESCOPE_ENABLED&quot; value=&quot;false&quot;/&gt;
  </code></pre>