Repository: s3rius/FastAPI-template (language: python)

Issue:
MySQL connection refused when pytest executed in github action
I created new FastAPI project with below command, and push it to my own repository to check github action working properly.
```shell
python3 -m fastapi_template --name test --description test --api-type rest --db mysql --orm sqlalchemy --ci github --redis --migrations --dummy --routers --swagger --sentry
```

But, github action keep throws same error in pytest stage.

`E       pymysql.err.OperationalError: (1044, "Access denied for user 'test'@'%' to database 'mysql'")`

I think it's related with 'localhost' problem, but not sure.


Discussion / hints:
You can see more [details](https://github.com/gwanryo/fastapi-aws-test/runs/7800680653?check_suite_focus=true#step:6:355) in my repository.

Hi, and thanks for creating an issue.

Oh, I'll try to investigate it later. Would you mind if I use your repo to validate my fixes?
@s3rius Not at all. First commit in my repo will be useful.
This issue is related with connection problem from local machine to internal docker.
https://stackoverflow.com/a/24326540
Ok. I found the root cause. 

Sorry, why it took so long to find it out. 

![image](https://user-images.githubusercontent.com/18153319/185923279-df708050-fb87-42bb-891c-f8558b0c5940.png)

I fixed it by changing some variables in docker container. This problem was caused because before running tests it creates database. But since in github actions I used variable `MYSQL_USER` and `MYSQL_PASSWORD`, instead of `MYSQL_ROOT_USER` and `MYSQL_ROOT_PASSWORD` it couldn't create test database. 

Also I forgot to add `MYSQL_AUTHENTICATION_PLUGIN: "mysql_native_password"`. These steps will fix your repo's builds.

Fix patch:
diff --git a/fastapi_template/input_model.py b/fastapi_template/input_model.py
index 4637c04..a88a40e 100644
--- a/fastapi_template/input_model.py
+++ b/fastapi_template/input_model.py
@@ -52,7 +52,7 @@ class Database(BaseModel):
     ),
     DatabaseType.postgresql: Database(
         name=DatabaseType.postgresql.value,
-        image="postgres:13.6-bullseye",
+        image="postgres:13.8-bullseye",
         async_driver="postgresql+asyncpg",
         driver_short="postgres",
         driver="postgresql",
@@ -60,7 +60,7 @@ class Database(BaseModel):
     ),
     DatabaseType.mysql: Database(
         name=DatabaseType.mysql.value,
-        image="bitnami/mysql:8.0.28",
+        image="bitnami/mysql:8.0.30",
         async_driver="mysql+aiomysql",
         driver_short="mysql",
         driver="mysql",


Test patch:
diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml b/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml
index 3bd082f..8974496 100644
--- a/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml
+++ b/fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml
@@ -62,17 +62,17 @@ jobs:
           POSTGRES_DB: {{ cookiecutter.project_name }}
           {%- endif %}
           {%- if cookiecutter.db_info.name == "mysql" %}
-          MYSQL_PASSWORD: {{ cookiecutter.project_name }}
-          MYSQL_USER: {{ cookiecutter.project_name }}
-          MYSQL_DATABASE: {{ cookiecutter.project_name }}
-          ALLOW_EMPTY_PASSWORD: yes
+          MYSQL_ROOT_PASSWORD: "{{ cookiecutter.project_name }}"
+          MYSQL_ROOT_USER: "{{ cookiecutter.project_name }}"
+          MYSQL_DATABASE: "{{ cookiecutter.project_name }}"
+          MYSQL_AUTHENTICATION_PLUGIN: "mysql_native_password"
           {%- endif %}
         {%- if cookiecutter.db_info.name == "mysql" %}
         options: >-
           --health-cmd="mysqladmin ping -u root"
           --health-interval=15s
           --health-timeout=5s
-          --health-retries=5
+          --health-retries=6
         {%- endif %}
         {%- if cookiecutter.db_info.name == "postgresql" %}
         options: >-