Multi-database service support

About 3 min...

Besides LeanCloud, Waline also supports a variety of databases, including MySQL, PostgreSQL, SQLite and MongoDB.

You only need to configure environment variables, and Waline will automatically switch to the corresponding data storage service based on the environment variables you configure.


https://mongodb.comopen in new window official provides 512M MongoDB database support for free. The following are the environment variables that need to be configured to use MongoDB database.

Environment VariableRequiredDefaultDescription
MONGO_DBMongoDB database name
MONGO_USERMongoDB server username
MONGO_PASSWORDMongoDB server password
MONGO_HOST127.0.0.1MongoDB server address, support array format
MONGO_PORT27017MongoDB server port, support array format
MONGO_OPT_SSLfalseuse SSL connection

Here is an example configuration for Please note that you need set as JSON style for MONGO_HOST and MONGO_PORT when you has multiple hosts.



Using MySQL to store data is also a good choice. Besides our own MySQL service, we can also use https://freedb.techopen in new window, which provides 100M of database support for free, or PlanetScaleopen in new window which provides 10GB.

If you want to use MySQL as storage, you need to import waline.sqlopen in new window first to create table and table structure, then set these environment variables in project.

Environment VariableRequiredDefaultDescription
MYSQL_DBMySQL database name
MYSQL_USERMySQL server username
MYSQL_PASSWORDMySQL server password
MYSQL_HOST127.0.0.1MySQL server address
MYSQL_PORT3306MySQL server port
MYSQL_PREFIXwl_MySQL table prefix
MYSQL_CHARSETutf8mb4MySQL table charset
MYSQL_SSLfalsewhether use SSL connection


TiDBopen in new window is an open source NewSQL database. TiDB Cloudopen in new window is the official online version, which provides 5GB of free quota for everyone to use.

Please refer to Create TiDB database to understand the initialization process.

Environment VariableRequiredDefaultDescription
TIDB_DBTiDB database name
TIDB_USERTiDB database user name
TIDB_PASSWORDTiDB database password
TIDB_HOST127.0.0.1Address of TiDB service
TIDB_PORT4000Port of TiDB service
TIDB_PREFIXwl_Table prefix of TiDB data table
TIDB_CHARSETutf8mb4TiDB data table character set


Download waline.sqliteopen in new window to your server if you want to use SQLite. Then set these environment variables in project.

Environment VariableRequiredDefaultDescription
SQLITE_PATHSQLite storage file path, not include file name
JWT_TOKENRandom String for login token generator
SQLITE_DBwalineSQLite storage file name, change it if your filename is not waline
SQLITE_PREFIXwl_SQLite table prefix


Supabaseopen in new window offers a free 512M database,while elephantSQLopen in new window provides 20M PG database support for free. Same as MySQL, you need to import waline.pgsqlopen in new window to create table and table structure before using PostgreSQL.

Environment VariableRequiredDefaultDescription
PG_DBPostgreSQL database name
PG_USERPostgreSQL server username
PG_PASSWORDPostgreSQL server password
PG_HOST127.0.0.1PostgreSQL server address
PG_PORT3211PostgreSQL server port
PG_PREFIXwl_PostgreSQL table prefix
PG_SSLfalseset to true to use SSL connection


Waline supports storing comment data in a CSV file on GitHub. To use GitHub as data storage, you need to apply for Personal access tokens. You can click Generate new token to apply it at in new window. Check the repo option in permission to obtain read and write permissions for repositories.

Environment VariableRequiredDefaultDescription
GITHUB_TOKENPersonal access tokensopen in new window
GITHUB_REPOrepository name, such as walinejs/waline
GITHUB_PATHThe data storage directory, such as data means it is stored in the data directory, root directory by default


Due to performance, using GitHub is not recommended.

Deta Base

Deta provides Deta Baseopen in new window free database support, which can be used even if it is not deployed on Deta. If deployed on Deta, there is no need to configure any environment variables. By default, Waline will use Deta Base as the database to store data. If it is deployed elsewhere, the following environment variables need to be configured.

Environment VariableRequiredDefaultDescription
DETA_PROJECT_KEYDeta project secret key


Besides above database storage, support for other storage services can also be added.

If you want to help Waline supporting more storage services, you can fork the project and inherit the base classopen in new window and then implement the select(), add(), update() and delete() methods of the corresponding storage service and submit the PR.

TIPS: The comment area is only for demo. If you have any questions, please go to Github Discussion to ask.
What do you think?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
  • Latest
  • Oldest
  • Hottest
Powered by Waline v2.14.7