4 Upgrade Uptime-Kuma to v2
ayakael edited this page 2025-11-07 18:18:13 +00:00

Uptime-Kuma v2 has many changes to the database structure which allows the use of mariadb

When running for the first time, it'll upgrade its sqlite3 dataae, which takes a while. You can follow the current state of migration via tail -f /var/log/uptime-kuma/uptime-kuma.log.

Migrating to mariadb

By default, uptime-kuma uses a file-based sqlite3 database. Starting with v2, we can use a mariadb database that improves performance when retaining a long history of statistics. Follow these steps to migrate from the sqlite3 file-based database to a mariadb-backed database:

  • shutdown uptime-kuma: service uptime-kuma stop
  • install mariadb: apk add mariadb mariadb-client
  • setup database: service mariadb setup
  • enable mariadb networking by making following change to /etc/my.cnf.d/mariadb-server.cnf:
diff --git a/etc/my.cnf.d/mariadb-server.cnf.orig b/etc/my.cnf.d/mariadb-server.cnf
index 24d5a5a..16807aa 100644
--- a/etc/my.cnf.d/mariadb-server.cnf.orig
+++ b/etc/my.cnf.d/mariadb-server.cnf
@@ -7,7 +7,7 @@
 
 # this is only for the mysqld standalone daemon
 [mysqld]
-skip-networking
+#skip-networking
 
 # Galera-related settings
 [galera]

  • start mariadb and add to boot: service mariadb start, rc-update add mariadb
  • while in mariadb client, create database and user with access. Make sure to note the password for later:
mariadb -u root
CREATE DATABASE uptime_kuma;
GRANT ALL PRIVILEGES ON uptime_kuma.* TO "uptime_kuma"@"localhost" IDENTIFIED BY "db-password";
FLUSH PRIVILEGES;
  • update /var/lib/uptime-kuma/db-config.json with following content:
{
	"type": "mariadb",
	"port": 3306,
	"host": "localhost",
	"username": "uptime_kuma",
	"password": "db-password",
	"dbName": "uptime_kuma"
}
  • start uptime-kuma to setup initial database tables: service uptime-kuma start
  • after initiable databse setup (check /var/log/uptime-kuma/uptime-kuma.log to make sure database is setup), shutdown uptime-kuma: service uptime-kuma stop
  • we will be using the sqlite3-to-mysql python application, which isn't available on Alpine. We thus need to install it in a virtual env using pip:
apk add py3-virtualenv
python3 -m venv /usr/local/lib/virtual-env
. /usr/local/lib/virtual-env/bin/activate
pip install sqlite3-to-mysql
  • finally, migrate /var/lib/uptime-kuma/kuma.db to mariadb: sqlite3mysql -f /var/lib/uptime-kuma/kuma.db -d uptime_kuma -u uptime_kuma -p -h 127.0.0.1 -K -i IGNORE
  • after database migration, restart uptime-kuma: service uptime-kuma start