【问题标题】:Docker How to completely reset MariaDB?Docker How to completely reset MariaDB?
【发布时间】:2023-01-06 21:28:48
【问题描述】:

I have MariaDB on docker

Trying to setup ssl I managed to completely break my user; I ended up with user duplicates and a new user called testssl

I tried resetting everything by deleting my database; deleting the image but nothing works. Every time I connect to the database and list users I get the same old list; testssl is still there

Where are those settings stored and how do I reset MariaDB to a completely clean state on my docker?

app:
    container_name: app
    image: "${APP_IMAGE}"
    restart: always
    build: build/app
    env_file: .env
    networks:
      - app_network
    volumes:
      - "${APP_HOST_DIR}:${APP_CONTAINER_DIR}"
    depends_on:
      - database

  database:
    container_name: mariadb
    image: "mariadb:${MARIADB_VERSION}"
    restart: always
    env_file: .env
    volumes:
      - "${SQL_INIT}:/docker-entrypoint-initdb.d"
      - type: bind
        source: ${MARIADB_DATA_DIR}
        target: /var/lib/mysql
      - type: bind
        source: ${MARIADB_LOG_DIR}
        target: /var/logs/mysql
      - type: bind
        source: ${MARIADB_CERTS_DIR}
        target: /etc/certs/
    environment:
      MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
      MYSQL_DATABASE: "${MYSQL_DATABASE}"
      MYSQL_USER: "${MYSQL_USER}"
      MYSQL_PASSWORD: "${MYSQL_PASSWORD}"

.env

MARIADB_DATA_DIR=./build/database/files/database
MARIADB_LOG_DIR=./build/database/files/logs
MARIADB_CERTS_DIR=./build/database/certs

【问题讨论】:

  • delete /var/lib/mysql & ./build/database/files/database
  • How did you get "user duplicates"? If you use create user this won't happen.

标签: docker mariadb


【解决方案1】:

MariaDB stores all of its runtime configuration (users, databases, etc.) in its data directory.

You've told your MariaDB container to use the host build/database/files/database directory for its data, so resetting the container won't do much since the data is, well, there.

Assuming the container is well-behaved and will initialize the database system if there's nothing in the data directory, you should be able to move that build/database/files/database folder to e.g. build/database/files/database.old, and create a new empty build/database/files/database, then retry.

【讨论】:

  • The paths are relative in his .env file.
  • @Marc Fixed already. Haven't had enough coffee yet.
【解决方案2】:

If you are using docker volumes you can:

  1. Rename the docker volume

    From

    mariadb:
    image: mariadb:10.6.11
    ...
    volumes:
      - mysqldataprevious:/var/lib/mysql
    ...
    

    To

    mariadb:
    image: mariadb:10.6.11
    ...
    volumes:
      - mysqldatanew:/var/lib/mysql
    ...
    
    1. Restart docker services

      docker-compose up -d

    2. Remove previous volume (optional)

      docker volume prune

    This will install a fresh mariadb in the new volume and withdocker volume pruneif your previous volume is not used by another container it will be deleted

【讨论】:

    猜你喜欢
    • 2022-12-27
    • 2022-12-27
    • 2022-12-19
    • 2022-12-02
    • 2022-12-28
    • 2022-12-02
    • 2022-12-02
    • 2022-12-01
    • 2011-04-06
    相关资源
    最近更新 更多