Database
MariaDB and SQLite3 — two engines, two jobs
Akadata Linux ships two database engines. MariaDB is the full relational server: multi‑user, concurrent, ACID‑compliant. SQLite3 is the embedded engine: zero configuration, single‑file, serverless. Use MariaDB when your application needs concurrent connections from multiple processes or services. Use SQLite3 when a single process owns its data and you want the simplest possible deployment.
PostgreSQL 18.4 is also packaged — postgresql-server, postgresql-client, and postgresql-contrib are available as stage4 APKs. Its deployment follows the upstream documentation; the package catalogue lists the exact APK names, digests, and licences.
MariaDB
Start, secure, and use
Generate unique secrets. Every code block below contains placeholder credentials such as <strong-root-password> and <app-user-password> that you must replace with strong, randomly generated values. Never reuse a placeholder. Never publish a real credential. Use openssl rand -base64 32 to generate a 256‑bit password and substitute it into every block that carries a placeholder.
Start the service
rc-service mariadb start
rc-update add mariadb
rc-statusSecure the installation
MariaDB ships with an empty root password and test databases. Run the secure‑installation script immediately:
mariadb-secure-installationThis prompts you for: a root password (set a strong one), removing anonymous users, disallowing remote root login, removing the test database, and reloading privileges. Answer yes to every prompt.
Set the root password manually
mariadb -u root
ALTER USER 'root'@'localhost' IDENTIFIED BY '<strong-root-password>';
FLUSH PRIVILEGES;
EXIT;After setting the password, you must authenticate:
mariadb -u root -pCreate a database
CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;utf8mb4 is the full Unicode character set. It supports emoji, CJK, and every script. Do not use the legacy utf8 alias; it only covers the Basic Multilingual Plane.
Create a user
CREATE USER 'myapp'@'localhost' IDENTIFIED BY '<app-user-password>';
GRANT ALL PRIVILEGES ON myapp.* TO 'myapp'@'localhost';
FLUSH PRIVILEGES;Restrict the user to localhost unless the application connects from another machine. For remote access, use 'myapp'@'10.0.0.%' or a specific IP.
Create a table and insert data
USE myapp;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;
INSERT INTO users (name, email) VALUES ('Ada Lovelace', 'ada@example.com');
SELECT * FROM users;Backup and restore
# Backup
mariadb-dump -u root -p myapp > /usr/local/backups/myapp-$(date +%Y%m%d).sql
# Restore
mariadb -u root -p myapp < /usr/local/backups/myapp-20260801.sql
# Backup all databases
mariadb-dump -u root -p --all-databases > /usr/local/backups/all-$(date +%Y%m%d).sqlConfiguration files
MariaDB reads configuration from /etc/my.cnf.d/. The main server configuration is in mariadb-server.cnf. Common adjustments:
# /etc/my.cnf.d/custom.cnf
[mysqld]
max_connections = 200
innodb_buffer_pool_size = 512M
innodb_log_file_size = 128M
character_set_server = utf8mb4
collation_server = utf8mb4_unicode_ci
[client]
default-character-set = utf8mb4Restart MariaDB after changing server configuration:
rc-service mariadb restartVerify the server is running
rc-service mariadb status
mariadb -u root -p -e 'SHOW VARIABLES LIKE "%version%";'
mariadb -u root -p -e 'SHOW DATABASES;'Application connections
Python — install pymysql in your venv:
pip install pymysqlimport pymysql
conn = pymysql.connect(
host='localhost',
user='myapp',
password='<app-user-password>',
database='myapp',
charset='utf8mb4'
)
with conn.cursor() as cur:
cur.execute('SELECT name, email FROM users')
for row in cur:
print(row)
conn.close()PHP — PDO with the pdo_mysql extension (installed with php85-pdo-mysql):
<?php
$pdo = new PDO(
'mysql:host=localhost;dbname=myapp;charset=utf8mb4',
'myapp',
'<app-user-password>'
);
$stmt = $pdo->query('SELECT name, email FROM users');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo $row['name'] . ' — ' . $row['email'] . "\n";
}Perl — install DBD::MariaDB via CPAN:
cpan> install DBD::MariaDBuse DBI;
my $dbh = DBI->connect(
'DBI:MariaDB:database=myapp;host=localhost',
'myapp',
'<app-user-password>'
) or die $DBI::errstr;
my $sth = $dbh->prepare('SELECT name, email FROM users');
$sth->execute();
while (my $row = $sth->fetchrow_hashref) {
print "$row->{name} — $row->{email}\n";
}
$dbh->disconnect;Node.js — install the mysql2 package globally or in your project:
npm install mysql2const mysql = require('mysql2');
const conn = mysql.createConnection({
host: 'localhost',
user: 'myapp',
password: '<app-user-password>',
database: 'myapp'
});
conn.query('SELECT name, email FROM users', (err, rows) => {
if (err) throw err;
rows.forEach(row => console.log(row.name + ' — ' + row.email));
conn.end();
});Man pages: man mariadb, man mariadb-dump, man mariadb-secure-installation. Full reference: mariadb.com/kb.
SQLite3
The embedded database
SQLite3 is a single‑file, serverless database. No daemon runs, no port is opened. The entire database (schema, indexes, and data) lives in one file. It is the right choice when a single process writes to the database and you want zero operational overhead.
Create and open a database
# Create a database file in /usr/local
sqlite3 /usr/local/db/myapp.dbCreate a table
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
created_at TEXT DEFAULT (datetime('now'))
);Insert and query
INSERT INTO users (name, email) VALUES ('Grace Hopper', 'grace@example.com');
INSERT INTO users (name, email) VALUES ('Alan Turing', 'alan@example.com');
SELECT * FROM users;
SELECT name FROM users WHERE email LIKE '%@example.com';Useful dot commands
.tables # List all tables
.schema users # Show the CREATE statement for a table
.mode column # Format output as columns
.headers on # Show column headers
.output out.txt # Redirect output to a file (then .output stdout to restore)
.quit # ExitPython with SQLite3
import sqlite3
conn = sqlite3.connect('/usr/local/db/myapp.db')
conn.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)')
conn.execute("INSERT INTO users (name) VALUES ('Margaret')")
conn.commit()
for row in conn.execute('SELECT * FROM users'):
print(row)
conn.close()When to choose SQLite3 over MariaDB
- Your application is a single process that owns its data.
- You do not need concurrent writes from multiple services.
- You want zero configuration: no daemon, no port, no users.
- Backups are as simple as copying the file.
- The dataset fits comfortably in memory or on a local SSD.
SQLite3 is the most deployed database engine in the world. It runs inside every smartphone, browser, and embedded device. It is not a toy. It handles terabyte‑scale databases and tens of thousands of queries per second when configured correctly.
Man page: man sqlite3. Full reference: sqlite.org/docs.html.
