Memos supports the following database types:
- SQLite (default)
- MySQL (Starting from version 0.16.1)
- PostgreSQL (Starting from version 0.18.0)
Using MySQL
MySQL version 8.0 or higher is recommended. Default charset and collation are
utf8mb4andutf8mb4_unicode_cirespectively.
By default, Memos continues to use SQLite as the default database driver. To switch to MySQL, you can use the following steps:
--driver mysql : This argument specifies that Memos should use the
mysqldriver instead of the defaultsqlite.--dsn dbuser:dbpass@tcp(dbhost)/dbname : Provides the connection details for your MySQL server.
You can start Memos with Docker using the following command:
docker run -d --name memos -p 5230:5230 -v ~/.memos/:/var/opt/memos neosmemo/memos:stable --driver mysql --dsn 'root:password@tcp(localhost)/memos_prod'
Additionally, you can set these configurations via environment variables:
MEMOS_DRIVER=mysql MEMOS_DSN=root:password@tcp(localhost)/memos_prod
Using PostgreSQL
Starting from version 0.18.0, Memos also supports PostgreSQL as a database driver. To switch to PostgreSQL, you can use the following steps:
--driver postgres : This argument specifies that Memos should use the
postgresdriver instead of the defaultsqlite.--dsn postgresql://postgres:PASSWORD@localhost:5432/memos : Provides the connection details for your PostgreSQL server.
You can start Memos with Docker using the following command:
docker run -d --name memos -p 5230:5230 -v ~/.memos/:/var/opt/memos neosmemo/memos:stable --driver postgres --dsn 'postgresql://postgres:PASSWORD@localhost:5432/memos'
Additionally, you can set these configurations via environment variables:
MEMOS_DRIVER=postgres MEMOS_DSN=postgresql://root:password@localhost:5432/memos
Note that if the PostgreSQL server is not configured to support SSL connections you will need to add ?sslmode=disable to the DSN.
Choose the database driver that best suits your needs and configure Memos accordingly.
Docker Compose Example
The compose.yml below demonstrates the usage of Memos with a PostgreSQL database.
version: "3.0"
services:
memos:
image: neosmemo/memos:stable
restart: always
depends_on:
- db
ports:
- 5230:5230
environment:
- MEMOS_DRIVER=postgres
- MEMOS_DSN=user=memos password=secret dbname=memosdb host=db sslmode=disable
db:
image: postgres:16.1
restart: unless-stopped
volumes:
- "./database:/var/lib/postgresql/data/"
environment:
POSTGRES_USER: memos
POSTGRES_PASSWORD: secret
POSTGRES_DB: memosdb
Migrating data between different drivers
You can do this with some scripting language, for example I used ChatGPT to help me implement a SQLite to MySQL Python script: SQLite to MySQL Migration.
Similarly, you can make a SQLite to PostgreSQL script.
