Can't connect to MySQL server on 'mariadb' | Temporary failure in name resolution

pymysql.err.OperationalError: (2003, “Can’t connect to MySQL server on ‘mariadb’ ([Errno -3] Temporary failure in name resolution)”)

I’m facing an a issue while runing the erpnext13 in my local below i attache the error logs

172.18.0.1 - - [06/Feb/2023 10:36:22] "POST /api/method/frappe.desk.reportview.get HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 613, in connect
    sock = socket.create_connection(
  File "/home/frappe/.pyenv/versions/3.10.5/lib/python3.10/socket.py", line 824, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/home/frappe/.pyenv/versions/3.10.5/lib/python3.10/socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/workspace/development/frappe-bench/apps/frappe/frappe/middlewares.py", line 18, in __call__
    return super(StaticDataMiddleware, self).__call__(environ, start_response)
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/werkzeug/middleware/shared_data.py", line 220, in __call__
    return self.app(environ, start_response)
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/werkzeug/middleware/shared_data.py", line 220, in __call__
    return self.app(environ, start_response)
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/werkzeug/local.py", line 231, in application
    return ClosingIterator(app(environ, start_response), self.cleanup)
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/werkzeug/wrappers/base_request.py", line 237, in application
    resp = f(*args[:-2] + (request,))
  File "/workspace/development/frappe-bench/apps/frappe/frappe/app.py", line 97, in application
    frappe.db.rollback()
  File "/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py", line 953, in rollback
    self.sql("rollback")
  File "/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py", line 161, in sql
    self.connect()
  File "/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py", line 85, in connect
    self._conn = self.get_connection()
  File "/workspace/development/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 76, in get_connection
    conn = pymysql.connect(
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 353, in __init__
    self.connect()
  File "/workspace/development/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 664, in connect
    raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'mariadb' ([Errno -3] Temporary failure in name resolution)")

After that I realised the docker container maridb was not running. then i restart the project for once again. it’s working after 30sec it’s automatically stopped.

Then I restarted the container. using this command

docker restart <CONTAINER_ID>

after a 30sec again the container stopped. Please help me to resolve the issue

Here a reference topic i had already created for the same issue CLICK HERE

if Mariadb has corrupted, only way is to reset data.

I’ve faced this issue with official mariadb:10.6 container, didn’t face it with bitnami/mariadb:10.6.

My guess is, it happens when the devcontainers are closed abruptly without proper signals. e.g. vs code crash when containers are running.

1 Like

reset data means restore the database of erpnext. I just deleted the MariaDB docker image and container and pull the other docjer image and run the command and im getting the same error

docker pull bitnami/mariadb:10.6

This is the command I used here a screenshot of the all the images

After that i changed the image in docker-compose.yml

Still im getting the error

:white_check_mark:TRY THIS SOLUTION :white_check_mark:

run this command in .devcontainer folder in terminal

docker-compose up -d

next step Restart the system and run the project

service will change if you use another image

refer this Custom docker-compose.yml for frappe_docker devcontainer ($2298024) · Snippets · Snippets · GitLab

1 Like

Again I’m facing the issue

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'mariadb' ([Errno -3] Temporary failure in name resolution)")

power cut was happen in my area the PC gets shutdown. and turn on the
PC and I’m getting this error please help me

After I edited the docker-compose.yml file what you have shared again im getting the same error. why it’s happening is because of I’m using the old volume as you mentioned?

version: "3.7"

services:
  mariadb:
    image: bitnami/mariadb:10.6
    restart: unless-stopped
    environment:
      MARIADB_CHARACTER_SET: utf8mb4
      MARIADB_COLLATE: utf8mb4_unicode_ci
      MARIADB_ROOT_PASSWORD: 123
      MARIADB_EXTRA_FLAGS: --skip-character-set-client-handshake --skip-innodb-read-only-compressed
    volumes:
      # - ${HOME}/data/mariadb:/bitnami/mariadb
      - mariadb-data:/bitnami/mariadb

  redis-cache:
    image: redis:alpine

  redis-queue:
    image: redis:alpine

  redis-socketio:
    image: redis:alpine

  frappe:
    image: frappe/bench:latest
    command: ["tail", "-f", "/dev/null"]
    environment:
      - SHELL=/bin/bash
      # For cypress testing
      # - DISPLAY=:14
      # - LIBGL_ALWAYS_INDIRECT=0
      # For docker
      # - DOCKER_HOST=docker
    volumes:
      - ..:/workspace:cached
      - ${HOME}/.ssh:/home/frappe/.ssh
    working_dir: /workspace/development
    ports:
      - 8000-8005:8000-8005
      - 9000-9005:9000-9005
    
volumes:
  mariadb-data:


Then I changed the volume to this for checking

mariadb-data-new

then I get this error Connection refused

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'mariadb' ([Errno 111] Connection refused)")

you can remove the old volumes and containers and start fresh.

docker stop $(docker ps -a -q) && docker system prune -f && docker volume prune -f

this command will stop containers, remove them, clean everything and remove volumes as well.

1 Like

:white_check_mark:TRY THIS SOLUTION :white_check_mark:

STEP 1:
Go To > .devcontainer file and change the volume name

mariadb-data → to → mariadb-data-new

Note: don’t change the container or anything. but I Used this. If you want you can use this also

version: "3.7"

services:
  mariadb:
    image: bitnami/mariadb:10.6
    restart: unless-stopped
    environment:
      MARIADB_CHARACTER_SET: utf8mb4
      MARIADB_COLLATE: utf8mb4_unicode_ci
      MARIADB_ROOT_PASSWORD: 123
      MARIADB_EXTRA_FLAGS: --skip-character-set-client-handshake --skip-innodb-read-only-compressed
    volumes:
      # - ${HOME}/data/mariadb:/bitnami/mariadb
      - mariadb-data:/bitnami/mariadb

  redis-cache:
    image: redis:alpine

  redis-queue:
    image: redis:alpine

  redis-socketio:
    image: redis:alpine

  frappe:
    image: frappe/bench:latest
    command: ["tail", "-f", "/dev/null"]
    environment:
      - SHELL=/bin/bash
      # For cypress testing
      # - DISPLAY=:14
      # - LIBGL_ALWAYS_INDIRECT=0
      # For docker
      # - DOCKER_HOST=docker
    volumes:
      - ..:/workspace:cached
      - ${HOME}/.ssh:/home/frappe/.ssh
    working_dir: /workspace/development
    ports:
      - 8000-8005:8000-8005
      - 9000-9005:9000-9005
    
volumes:
  mariadb-data:

STEP 2
Start the Project Reopen in container and do bench start

STEP 3
Use this command

bench ues <YOUR_SITE_NAME>

STEP 4

bench restore <YOUR_DATABASE_BACKUP_SQL_PATH>

STEP 5

bench migrate

bench build

Restart the project you will get it