Unable to connect to Mysql server -- No connection could be made because the target machine actively refused it

Please see the following config.yml.
The job db-setup can be run successfully. When it runs build-and-test, it failed at “Run tests” because it cannot connect to the mysql database. The error is

MySql.Data.MySqlClient.MySqlException : Unable to connect to any of the specified MySQL hosts.
-------- System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it.

The test tried to connect to the mysql server using the ip address 127.0.0.1.

I am not sure if one container can connect to the MySQL server which is in another container.
I searched from the web but still cannot find the solution.
Can anyone help?

version: 2.1

orbs:
  win: circleci/windows@5.0.0

jobs:
  db-setup:
    working_directory: /home/circleci/code/projectxxx
    docker:
      - image: cimg/base:2022.12
      - image: cimg/mysql:8.0
        environment:
          MYSQL_ROOT_PASSWORD: rootpwd
          MYSQL_DATABASE: testdb
          MYSQL_USER: user
          MYSQL_PASSWORD: pwd
    steps:
      # Checkout the code as the first step.
      - checkout
      - run:
      # Our primary container isn't MYSQL so run a sleep command until it's ready.
          name: Waiting for MySQL to be ready
          command: |
            for i in `seq 1 10`;
            do
              nc -z 127.0.0.1 3306 && echo Success && exit 0
              echo -n .
              sleep 1
            done
            echo Failed waiting for MySQL && exit 1
      - run:
          name: Install MySQL CLI
          command: |
            sudo apt update
            sudo apt-get install mysql-client
      - run:
          name: "Run migrations"
          command: |
            cd db/migration
            for FILE in *; do mysql -h 127.0.0.1 -u user -ppwd testdb < $FILE; done;
            

  build-and-test:
    executor:
      name: win/default
    working_directory: C:\Users\circleci\code\projectxxx\app

    steps:
      # Checkout the code as the first step.
      - checkout:
          path: C:\Users\circleci\code\projectxxx
      - run:
          name: "Set environment variables"
          command: echo APP_ENV=Test > ./../.env
      - restore_cache:
          keys:
            - dotnet-packages-v1-{{ checksum "projectxxx.Core\\projectxxx.Core.csproj" }}
      - run:
          name: "Install project dependencies"
          command: dotnet.exe restore
      - save_cache:
          paths:
            - C:\Users\circleci\code\projectxxx\.nuget\packages
          key: dotnet-packages-v1-{{ checksum "projectxxx.Core\\projectxxx.Core.csproj" }}
      - run:
          name: "Run Build step"
          command: dotnet.exe publish -c Release -r win10-x64
      - store_artifacts:
          path: ./projectxxx.ConsoleApp/bin/Release/netcoreapp6/win10-x64/publish/projectxxx.ConsoleApp.exe
      - run:
          name: "Create config file"
          command: ./../circleCiScripts/createConfigFile.sh Test
      - run:
          name: "Show appsetting.json"
          command: |
            tail "./projectxxx.Tests/bin/debug/netcoreapp6/appsettings.test.json"
      - run:
          name: "Run tests"
          command: |
            dotnet test

workflows:
  projectxxx: 
    jobs:
      - db-setup
      - build-and-test:
          requires:
            - db-setup