Skip to content

Migrating from MySQL and MariaDB

Benjamin Jonard edited this page Nov 24, 2026 · 1 revision

⚠️ Starting with version 1.10, Koillection will no longer support MySQL and MariaDB. If you are using one of them, you need to migrate your data to PostgreSQL before upgrading to 1.10.

Koillection 1.9 provides a command that copies all your data from your MySQL or MariaDB database to a new PostgreSQL database. Your MySQL database is only read, never modified. Your /uploads folder is not affected.

The examples below are based on the docker-compose.yml and .env files from the Installation page, where the MySQL service is called db. Adapt them to your own setup.

Step 1 -> Backup your database

Please backup your MySQL or MariaDB database before going any further.

Step 2 -> Update Koillection to the latest 1.9 version

Update Koillection to the latest 1.9 version as described in the Updating page, and keep using your MySQL database.

Koillection updates your MySQL database when the container starts. The migration command only works on an up to date database.

Step 3 -> Add a PostgreSQL service

Add a new service to your docker-compose.yml file, next to the existing db service. Don't change your .env file yet, Koillection must keep using MySQL for now.

    postgresql:
        image: postgres:18
        container_name: postgresql
        restart: unless-stopped
        environment:
            - POSTGRES_DB=koillection
            - POSTGRES_USER=koillection
            - POSTGRES_PASSWORD=change_me!
        volumes:
            - "./volumes/postgresql:/var/lib/postgresql/data"

Then start it:

docker-compose up -d

Step 4 -> Run the migration

⚠️ Don't use Koillection while the migration is running. Changes made during the migration won't be copied to PostgreSQL.

docker exec -it --user koillection koillection bin/console app:migrate-from-mysql "postgresql://koillection:change_me!@postgresql:5432/koillection"

The URL contains the user, the password, the host, the port and the name of your PostgreSQL database, as defined in step 3. If your password contains special characters like @, :, / or #, you must URL-encode them.

The command asks you to confirm that you have a backup, then:

  1. Checks that your MySQL database is up to date and that the PostgreSQL database is empty
  2. Creates the tables in the PostgreSQL database
  3. Copies all your data, table by table, and checks that every row was copied

If something goes wrong, nothing is copied. Drop and recreate the PostgreSQL database before running the command again:

docker exec -it postgresql psql -U koillection -d postgres -c "DROP DATABASE koillection" -c "CREATE DATABASE koillection"

Step 5 -> Switch Koillection to PostgreSQL

Update the database section of your .env file:

DB_DRIVER=pdo_pgsql
DB_NAME=koillection
DB_HOST=postgresql
DB_PORT=5432
DB_USER=koillection
DB_PASSWORD=change_me!
DB_VERSION=18

Then recreate the Koillection container:

docker-compose up -d --force-recreate koillection

Step 6 -> Check your data

Log in and check that your collections, items and images are there.

Once you are sure everything is fine, you can remove the db service from your docker-compose.yml file. Keep your backup for a while.

Clone this wiki locally