#πŸ”’ Mariadb connection failure

27 messages Β· Page 1 of 1 (latest)

spare spoke
#

I have a fairly simple job that looks like this:

jobs:
  test:
    name: Ubuntu / Py3.11
    runs-on: ubuntu-latest

    services:
      mariadb:
        image: mariadb:latest
        ports:
          - 3307:3306
        env:
          MARIADB_ROOT_HOST: 127.0.0.1
          MYSQL_ROOT_PASSWORD: rootpassword
          MYSQL_DATABASE: mydatabase
          MYSQL_USER: root
          MYSQL_PASSWORD: mydatabasepass

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
   
      - name: Install the project dependencies
        run: poetry install

      - name: Create dummy user
        run: poetry run python ./scripts/testdb.py          

      - name: Run tests
        run: poetry run pytest -vv
# ./scripts/testdb.py
import pymysql

connection = pymysql.connect(
    host="127.0.0.1",
    port=3307,
    user="root",
    password="mydatabasepass",
    database="mydatabase",
)

This however, raises pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 111] Connection refused)"). I'm unsure as to what's wrong here.
@fading path I made a repo over at https://github.com/Ravencentric/mariadbtest/actions for demonstration and it seems to succeed. The exact same thing fails in gitea

vernal saffronBOT
#

@spare spoke

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

drifting canyon
#

are you sure the port is correct?

#

hm, right, it is

fiery galleon
#

Add a step to wait for the MariaDB service to be ready before running your testdb.py file like fr that is sometjing important.

spare spoke
fading path
#

@spare spoke

#

I think you need login as root

spare spoke
#

Ill try this and get back to you

charred sundial
#

I could be tripping, but I don't think the IP should be 127.0.0.1. Your container will have its own IP.

#

Wait, is this a container config?

fading path
#

Mostly, it runs on GitHub Actions, so you can also refer to it as a container

charred sundial
#

Ya, I managed to find that using "runs-on". I'm assuming that container will have its own IP.

#

Ya, if I start a container, it's on its own network with its own IP:

#

I had to check. It's been a while since I've used docker.

fading path
#

You’re right. So need to define the ports: 3307:3306 in the configuration file to specify which port to connect to.

charred sundial
#

I was thinking they'd need to lookup the IP the container is using, and then use that IP in their script.

fading path
charred sundial
#

Oh, nvm. I forgot about that forwarding.

spare spoke
#

im guessing there's some configuration issue at this point

#

been smashing my head at this for a whole day now

spare spoke
#
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")
vernal saffronBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.