Skip to content

Configure existing database

F43nd1r edited this page Mar 28, 2024 · 6 revisions

Database Setup

This tutorial shows how to change the default setup to use your own database instead of one inside docker.

1. Configure Database

1.1 Mysql configuration

[mysqld]
log-bin-trust-function-creators = 1

1.2 Create database and user

CREATE DATABASE acrarium CHARACTER SET utf8mb4;
CREATE USER acrarium IDENTIFIED BY '[[secure_password]]';
GRANT ALL PRIVILEGES ON acrarium.* TO acrarium@localhost identified by '[[secure_password]]';

2. Adjust your configuration

Follow 2.a if using docker, 2.b otherwise.

2.a Adjust docker-compose

Use the default docker-compose from Step 2 of the Setup guide, removing the database service.

Then add

    extra_hosts:
      host.docker.internal: host-gateway

to the acrarium service if your database is running on localhost.

And adjust your environment:

        environment:
            SPRING_DATASOURCE_URL: jdbc:mysql://host.docker.internal:3306/acrarium?useSSL=false&allowPublicKeyRetrieval=true&useLegacyDatetimeCode=false&serverTimezone=UTC
            SPRING_DATASOURCE_USERNAME: acrarium
            SPRING_DATASOURCE_PASSWORD: [[secure_password]]

2.b Adjust application.properties

# spring.datasource.url=jdbc:mysql://<sql host>:<sql port>/<database name>?useSSL=false&allowPublicKeyRetrieval=true&useLegacyDatetimeCode=false&serverTimezone=UTC, e.g.
spring.datasource.url=jdbc:mysql://localhost:3306/acrarium?useSSL=false&allowPublicKeyRetrieval=true&useLegacyDatetimeCode=false&serverTimezone=UTC
# spring.datasource.username=<sql user name>, e.g.
spring.datasource.username=acrarium
# spring.datasource.password=<sql user password>, e.g.
spring.datasource.password=[[secure_password]]