Search code examples
mysqlcontinuous-integrationgithub-actions

Can't connect to local MySQL server through socket because Access denied


I am trying to get a coverage report in GitHub Actions

but when I run the pipeline I gives me this error:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock

Then I search around add added the sudo mysql start service and now I get this error, but I don't know were or have to write mit -root -password and the -host?

Access denied for user 'root'@'localhost' (using password: YES)")

how do I do that?

name: Django CI

on:
  push:
    branches: [ unittests ]
    paths-ignore: '**/SkoleProtocol/attendanceCode/tests/test_selenium.py'
  pull_request:
    branches: [ unittests ]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.7, 3.8, 3.9]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.7
      uses: actions/setup-python@v2
      with:
        python-version: 3.7
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Create test database
      run: |
        sudo service mysql start
    - name: Coverage report
      run: |
        pip install coverage
        coverage run manage.py test
        coverage report
    - name: Lint with flake8
      run: |
        pip install flake8
        flake8 ./attendanceCode --exit-zero # Exit with status code "0" even if there are errors.
    - name: Django Tests
      run: |
        python3 manage.py test


Solution

  • Two things that stand out.

    • Do you happen to have the credentials in an env file else where?

    - name: Create test database
          run: |
            sudo service mysql start

    You just happen to start the service rather than creating the database. Try:

    sudo /etc/init.d/mysql start // To start the service
    mysql -uroot -proot -e "CREATE DATABASE __dbname__;"