0

I have been trying to automate my test and deployment for my portfolio project with GitHub actions for the past two days, and i am new to it. i wrote a script to set up a test environment for a python application and i used an external action to get mysql set up on the runner, and i keep getting an access denied error when i try to access the database from root or any user i created during the setup of the database, i was thinking maybe there is a conflict in character types, because i used the same password, i even tried setting the password in github secretes and calling it as a variable but still got the same thing.

this is the workflow file for a python application and i used an external action to get mysql set up on the runner here is the workflow file

main.yml

name: test-deploy-app
run-name: ${{ github.actor }} is deploying  to server
on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]
jobs:
  run-test:
    runs-on: ubuntu-latest
    env:
        SH_HOST: 'localhost'
        SH_PWD: 'Sch_t3st_#3#_pwd'
        SH_USER: 'sh_test_user'
        SH_ENV: 'test'
        SH_DATABASE: 'sh_test_db'
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v3
        with:
          python-version: "3.8"

      - uses: mirromutth/mysql-action@v1.1
        with:
          host port: 3800 # Optional, default value is 3306. The port of host
          container port: 3307 # Optional, default value is 3306. The port of container
          character set server: 'utf8' # Optional, default value is 'utf8mb4'. The '--character-set-server' option for mysqld
          collation server: 'utf8_general_ci' # Optional, default value is 'utf8mb4_general_ci'. The '--collation-server' option for mysqld
          mysql version: '8.0' # Optional, default value is "latest". The version of the MySQL
          mysql database: 'sh_test_db' # Optional, default value is "test". The specified database which will be create
          mysql root password: 'password' # Required if "mysql user" is empty, default is empty. The root superuser password
          mysql user: 'developer' # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Can use secrets, too
          mysql password: 'me' # Required if "mysql user" exists. The password for the "mysql user"
      - run: mysql --version
      - run: ls
      - run: sudo apt-get install libmysqlclient-dev
      - run: sudo apt-get install zlib1g-dev
      - run: pip3 install mysqlclient
      - run: pip3 install SQLAlchemy
      - run: sudo systemctl start mysql.service
      - run: cat setup_mysql_test.sql | sudo mysql -u root --password=password
      - name: start test
        run: python3 -m unittest discover

I tried this to set up and test my python application using unittest, but i always get a mysql access error showing that my password is wrong, on the line that has this code cat setup_mysql_test.sql | sudo mysql -u root --password==password

i also tried a different approach where i installed the mysql server my self without an external action and i pre seeded the installation root password with debconf-set-selections but i still got the same response of access denied. below if the workflow visualization showing the error

workflow vizualisation

the file that contains the test sql script i am trying to pass to the database

setup_mysql_test.sql

-- prepares a MySQL server for the project for testing

CREATE DATABASE IF NOT EXISTS sh_test_db;
CREATE USER IF NOT EXISTS 'sh_test_user'@'localhost' IDENTIFIED BY 'Sch_t3st_#3#_pwd';
GRANT ALL PRIVILEGES ON `sh_test_db`.* TO 'sh_test_user'@'localhost';
GRANT SELECT ON `performance_schema`.* TO 'sh_test_user'@'localhost';
FLUSH PRIVILEGES;

this will create the test database and the test user.

all i am trying to do is setup a mysql database and execute this mysql command to configure a database and user that the sqlalchemy orm from my application can use.

also, i tried changing the port on the container and host to 3306 which i thought to be mysql default port but then it refuses to start and fails on this run command on the workflow sudo systemctl start mysql.service giving me this error,

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I would be very gratefull to whoever can help, i am so close to my deadline thanks

reinhard
  • 1
  • 2
  • Relevant: https://stackoverflow.com/questions/75541794/how-to-grant-permissions-to-mysql-in-github-actions and https://stackoverflow.com/questions/75169859/mysql-import-error-in-github-actions-with-laravel. – Azeem Mar 30 '23 at 09:53
  • 1
    Thanks, I used the pre installed mysql server and it worked fine.. I never knew the runner had those. Thanks @Azeem – reinhard Mar 30 '23 at 12:20

1 Answers1

0

I have solved this issue. needs to update the mysql client.

- name: install mysql client
        run: |
          sudo apt-get update
          sudo apt-get install -y  mysql-client