Using the MariaDB (MySQL) Backend
しぐれ edited on Mar 15, 2025.
⚠️ 💩 ⚠️
Although MySQL database works fine, be aware that our builds are based upon MariaDB client libraries since that is what Debian provides.
⚠️ 💩 ⚠️
To use the MariaDB (MySQL) backend, you can either use the official Docker image or build your own binary with MySQL enabled.
To run the binary or container, ensure the DATABASE_URL environment variable is set (i.e. DATABASE_URL='mysql://<user>:<password>@mysql/vaultwarden[?ssl_mode=(disabled|required|preferred)&ssl_ca=/path/to/cart.(crt|pem)]').
Connection String Syntax:
If your password contains special characters, you will need to use percentage encoding.
| ! | # | $ | % | & | ' | ( | ) | * | + | , | / | : | ; | = | ? | @ | [ | ] |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| %21 | %23 | %24 | %25 | %26 | %27 | %28 | %29 | %2A | %2B | %2C | %2F | %3A | %3B | %3D | %3F | %40 | %5B | %5D |
A complete list of codes can be found on Wikipedia page for percent encoding
Example using Docker
Example using Non-Docker MySQL Server
Example using docker-compose
Manually create a database (For example, using an existing database server)
To execute these queries you need a user which has the privileges to create new databases and users.
Most of the time that would be the root user, but it could be different for your database.
Create database and user
- Create an new (empty) database for vaultwarden (Ensure the Charset and Collate are correct!):
CREATE DATABASE vaultwarden CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
- Create a new database user and grant rights to database (MariaDB, MySQL):
CREATE USER 'vaultwarden'@'localhost' IDENTIFIED BY 'yourpassword'; GRANT ALL ON `vaultwarden`.* TO 'vaultwarden'@'localhost'; FLUSH PRIVILEGES;
You might want to try a restricted set of grants:
Migrating from SQLite to MySQL
An easy way of migrating from SQLite to MySQL has been described in this issue comment. The steps are repeated below. Please, note that you are using this at your own risk and you are strongly advised to backup your installation and data!
- First follow the steps 1 and 2 above
- Configure vaultwarden and start it, so diesel can run migrations and set up the schema properly. Do not do anything else.
- Stop vaultwarden.
- Dump your existing SQLite database using the following command. Double check the name of your sqlite database, default should be db.sqlite.
Note: You need the sqlite3 command installed on your Linux system.
We need to remove some queries from the output of the sqlite dump like create table etc.. we will do that here.
You either can use this one-liner:sqlite3 db.sqlite3 .dump | grep "^INSERT INTO" | grep -v "__diesel_schema_migrations" > sqlitedump.sql ; echo -ne "SET FOREIGN_KEY_CHECKS=0;\n$(cat sqlitedump.sql)" > mysqldump.sqlOr the following right after each other:sqlite3 db.sqlite3 .dump | grep "^INSERT INTO" | grep -v "__diesel_schema_migrations" > sqlitedump.sql echo "SET FOREIGN_KEY_CHECKS=0;" > mysqldump.sql cat sqlitedump.sql >> mysqldump.sql - Load your MySQL dump:
mysql --force --password --user=vaultwarden --database=vaultwarden < mysqldump.sql
- Start vaultwarden again.
Note: Loading your MySQL dump with --show-warnings will highlight that the datetime fields are getting truncated during the import which seems to be okay.
Note 1:Then error loading data mysqldump.sql Load error
Note 2: If MariaDB might complain about mismatched value counts if SQLite database is migrated from a prior, older version, e.g.:
sqlite3