Skip to content

Migrating from MariaDB (MySQL) to SQLite

Martin Böh edited this page Nov 3, 2024 · 7 revisions

Warning

⚠️ ☠️ ⚠️

Use these commands at your own risk!
Always create a backup before you do anything which could destroy your whole vault!

⚠️ ☠️ ⚠️


General

Vaultwarden was designed at first using SQLite only, but at the time both MariaDB (MySQL) and PostgreSQL also were added into the mix. For SQLite you do not have to run a separate server or container, while for the other two you do need to run something extra.

Now, what if you started out using MariaDB and want to go back to SQLite? Well, that is possible, but there could be some quirks which we do not know of using the steps below. If you encounter anything strange with this and need help, or even solved it, please open a new discussion here: https://github.com/dani-garcia/vaultwarden/discussions to help you and others.

How to migrate from MariaDB to SQLite

Make sure you are using the same version of Vaultwarden (Docker or custom build) for both SQLite and MariaDB, don't update the Docker image in-between these steps. To migrate to SQLite we first need to have a SQLite database file which we can use to transfer the data to. For this file to be created you need to stop your current Vaultwarden instance, and configure it to use SQLite. You can do this by changing your DATABASE_URL from DATABASE_URL=mysql://<vaultwarden_user>:<vaultwarden_pw>@mariadb/vaultwarden to DATABASE_URL=/data/db.sqlite3 for example. ( /data is the internal path within the Docker container of the -v volume you use).

After you have changed the config, start Vaultwarden and it should show you that it executed a few migrations by checking the logs for lines which start with Executing migration script .....

Now stop Vaultwarden again so that you can start the migration. You need the database host and credentials you used for MariaDB to continue.

Now run the following one-liner and adjust the <dbhost>, <dbuser> and <database> to what you used for your MariaDB connection.

mysqldump \
  --host=<dbhost> \
  --user=<dbuser> --password \
  --skip-create-options \
  --compatible=ansi \
  --default-character-set=utf8 \
  --skip-extended-insert \
  --compact \
  --single-transaction \
  --no-create-db \
  --no-create-info \
  --hex-blob <database> \
  | grep -a "^INSERT INTO" | grep -a -v "__diesel_schema_migrations" \
  | sed 's#\\"#"#gm' \
  | sed -sE "s#,0x([^,]*)#,X'\L\1'#gm" \
   > mysql-to-sqlite.sql

You should be prompted to enter a password, enter your password and press enter.

This should generate a file mysql-to-sqlite.sql which holds your database. Now look for the db.sqlite3 file Vaultwarden created in the previous step when you started Vaultwarden for the first time using SQLite as it's database. Copy or move mysql-to-sqlite.sql to the same directory as db.sqlite3. Now you can execute the following

sqlite3 db.sqlite3 < mysql-to-sqlite.sql

This should have filled the SQLite database with the dump, and you can now start Vaultwarden again using SQLite instead of MySQL.

FAQs

  1. FAQs
  2. Audits

Container Image Usage

  1. Which container image to use
  2. Starting a container
  3. Updating the vaultwarden image
  4. Using Docker Compose
  5. Using Podman

Deployment

  1. Building your own docker image
  2. Building binary
  3. Pre-built binaries
  4. Third-party packages
  5. Deployment examples
  6. Proxy examples
  7. Logrotate example

HTTPS

  1. Enabling HTTPS
  2. Running a private vaultwarden instance with Let's Encrypt certs

Configuration

  1. Overview
  2. Disable registration of new users
  3. Disable invitations
  4. Enabling admin page
  5. Disable the admin token
  6. Enabling WebSocket notifications
  7. Enabling Mobile Client push notification
  8. Enabling U2F and FIDO2 WebAuthn authentication
  9. Enabling YubiKey OTP authentication
  10. Changing persistent data location
  11. Changing the API request size limit
  12. Changing the number of workers
  13. SMTP configuration
  14. Password hint display
  15. Disabling or overriding the Vault interface hosting
  16. Logging
  17. Creating a systemd service
  18. Syncing users from LDAP
  19. Using an alternate base dir (subdir/subpath)
  20. Other configuration

Database

  1. Using the MariaDB (MySQL) Backend
  2. Using the PostgreSQL Backend
  3. Running without WAL enabled
  4. Migrating from MariaDB (MySQL) to SQLite

Security

  1. Hardening Guide
  2. Fail2Ban Setup
  3. Fail2Ban + ModSecurity + Traefik + Docker

Other

  1. Translating the email templates
  2. Translating admin page
  3. Customize Vaultwarden CSS

Backup

  1. General (not docker)

Other Information

  1. Importing data from Keepass or KeepassX
  2. Backing up your vault
  3. Differences from the upstream API implementation
  4. Supporting upstream development
  5. Caddy 2.x with Cloudflare DNS
  6. Git hooks
Clone this wiki locally