πŸ’ΎDatabase

Complete guide to configuring SQLite and MySQL databases for BlackMarket.

Overview

BlackMarket supports two database systems:

  • SQLite - File-based, no setup required (default)

  • MySQL - Server-based, better for large servers/networks


SQLite Configuration

Overview

SQLite is the default database system. It's:

  • βœ… Zero configuration required

  • βœ… Perfect for single servers

  • βœ… Automatic backups possible

  • βœ… No external dependencies

  • ⚠️ Not ideal for cross-server networks

  • ⚠️ Lower performance on very large datasets

Configuration

File Location

Backing Up SQLite

Manual Backup:

Automated Backup Script (Linux):

Add to crontab:


MySQL Configuration

Overview

MySQL is recommended for:

  • βœ… Large servers (1000+ players)

  • βœ… Cross-server networks (with Redis)

  • βœ… Better performance at scale

  • βœ… Advanced backup options

  • ⚠️ Requires external MySQL server

  • ⚠️ More complex setup

Prerequisites

  1. MySQL Server (5.7+) or MariaDB (10.2+)

  2. Database created for BlackMarket

  3. User with permissions

Step 1: Create Database

Connect to MySQL:

Create database and user:

Step 2: Configure Plugin

Step 3: Restart Server

The plugin will automatically create all required tables on first connection.


MySQL Advanced Configuration

Remote MySQL Server

If MySQL is on a different server:

Create remote user:

SSL Connection

For secure connections:

MySQL must have SSL enabled and certificates configured.

Connection Pooling

BlackMarket uses HikariCP for connection pooling. Default settings:

These are optimized for most servers and cannot be changed without code modification.


Database Migration

SQLite to MySQL

Step 1: Check current data:

Step 2: Run migration:

Step 3: Confirm migration:

Step 4: Wait for completion:

Step 5: Update config:

Step 6: Reload:

MySQL to SQLite

Same process, just specify sqlite:

Then update config:

Migration Safety

βœ… What's migrated:

  • Player data

  • Purchase history

  • Player market items (per-player mode)

  • Global market items

  • Item sold counts

  • Cooldown data

  • One-time purchase flags

  • Last reset times

βœ… Backup created: Original database is not modified

⚠️ Always backup before migration:


Database Tables

BlackMarket creates these tables automatically:

player_data

Stores basic player information.

Column
Type
Description

uuid

VARCHAR(36)

Player UUID (primary key)

last_reset

BIGINT

Last market reset timestamp

player_purchases

Tracks player purchases and cooldowns.

Column
Type
Description

uuid

VARCHAR(36)

Player UUID

item_key

VARCHAR(64)

Item identifier

bought

BOOLEAN

Whether player bought item

cooldown_end

BIGINT

Cooldown end timestamp

Primary Key: (uuid, item_key)

player_market_items

Stores per-player market items (per-player mode only).

Column
Type
Description

uuid

VARCHAR(36)

Player UUID

item_key

VARCHAR(64)

Item identifier

Primary Key: (uuid, item_key)

global_market_items

Stores current global market items.

Column
Type
Description

item_key

VARCHAR(64)

Item identifier (primary key)

item_sold_count

Tracks how many times each item has been sold.

Column
Type
Description

item_key

VARCHAR(64)

Item identifier (primary key)

sold_count

INT

Times sold

purchase_history

Complete purchase history log.

Column
Type
Description

id

INT

Auto-increment ID

uuid

VARCHAR(36)

Player UUID

item_key

VARCHAR(64)

Item identifier

price

DOUBLE

Purchase price

timestamp

BIGINT

Purchase timestamp

global_settings

Stores global plugin settings.

Column
Type
Description

setting_key

VARCHAR(64)

Setting name (primary key)

setting_value

TEXT

Setting value


Database Maintenance

MySQL Optimization

Analyze tables (improves query performance):

Optimize tables (defragments and repairs):

Add to cron (run weekly):

SQLite Optimization

Vacuum database (reclaims space):


Backup Strategies

SQLite Backups

Option 1: Simple Copy

Option 2: SQLite Backup Command

Option 3: Plugin Backup (via backup plugin)

  • Use plugins like SimpleBackup or AutoSaveWorld

  • Include plugins/BlackMarket/database.db in backup

MySQL Backups

Full Database Backup:

Compressed Backup:

Automated Daily Backup:


Restore from Backup

SQLite Restore

MySQL Restore


Troubleshooting

Issue 1: MySQL Connection Failed

Error: Failed to connect to database!

Solutions:

  1. Check credentials:

  1. Verify MySQL is running:

  1. Check MySQL port:

  1. Test connection manually:

  1. Check firewall (for remote MySQL):

Issue 2: Access Denied

Error: Access denied for user 'blackmarket'@'localhost'

Solution: Grant proper permissions

Issue 3: Too Many Connections

Error: Too many connections

Solution: Increase MySQL max connections

Or in my.cnf:

Issue 4: SQLite Database Locked

Error: Database is locked

Solution:

  1. Ensure server is fully stopped

  2. Check no other processes are using the file:

  1. If needed, restart server

Issue 5: Slow Queries

MySQL: Enable slow query log

SQLite: Consider migrating to MySQL for better performance


Performance Tips

MySQL

  1. Use InnoDB engine (default in BlackMarket)

  2. Optimize tables regularly

  3. Use SSD storage

  4. Increase buffer pool:

SQLite

  1. Use SSD storage

  2. Regular VACUUM operations

  3. Keep database file small

  4. Consider MySQL for 500+ players


Database Monitoring

Check Database Size

MySQL:

SQLite:

Check Table Sizes

MySQL:

Monitor Connections

MySQL:


Next Steps

Last updated