Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:APIJSON APIJSON Demo MySQL

From Leeroopedia
Knowledge Sources
Domains Database, Infrastructure
Last Updated 2026-10-14 00:00 GMT

Overview

MySQL 8.0+ relational database with Druid 1.2.9 connection pooling, serving as the primary data store for the APIJSON Demo server.

Description

This environment provides a MySQL database connection via the Alibaba Druid connection pool. The default database type is MySQL (with TiDB, MariaDB, OceanBase compatibility noted in source). The demo also supports PostgreSQL via HikariCP, but the primary configuration uses Druid with three datasource beans: DRUID (primary), DRUID-TEST (test), and DRUID-ONLINE (production/online). Connection pooling is configured with initial size 5, min idle 5, max active 20, and prepared statement pooling enabled.

Usage

Use this environment for any implementation that directly configures or queries the database: DemoSQLConfig, DemoSQLExecutor, and DemoDataSourceConfig. The @datasource keyword in APIJSON requests selects which Druid pool to use at runtime.

System Requirements

Category Requirement Notes
OS Linux / macOS / Windows Any OS supporting MySQL
Hardware 2GB RAM minimum MySQL server process
Disk 5GB SSD For MySQL data directory and schema

Dependencies

System Packages

  • MySQL Server 8.0+ (or compatible: TiDB, MariaDB, OceanBase)
  • PostgreSQL 9.6.15+ (optional, via HikariCP datasource)

Java Packages

  • `mysql-connector-j` = 9.2.0
  • `postgresql` = 42.7.3
  • `druid` = 1.2.9
  • `jtds` = 1.3.1 (SQL Server, optional)
  • `sqlite-jdbc` = 3.39.3.0 (optional)

Credentials

Database credentials are configured in `application.yml` and `DemoSQLConfig.java`:

  • `spring.datasource.druid.username` / `gainDBAccount()` — MySQL username (default: `root`)
  • `spring.datasource.druid.password` / `gainDBPassword()` — MySQL password (default: `apijson`)
  • `spring.datasource.hikari.username` — PostgreSQL username (default: `postgres`)

Warning: The demo contains default credentials. Always change these in production.

Quick Install

# MySQL setup (Ubuntu/Debian)
sudo apt install mysql-server
sudo mysql -e "CREATE DATABASE sys; CREATE USER 'root'@'localhost' IDENTIFIED BY 'apijson'; GRANT ALL ON *.* TO 'root'@'localhost';"

# PostgreSQL setup (optional)
sudo apt install postgresql

Code Evidence

Default database type from `DemoSQLConfig.java:54`:

DEFAULT_DATABASE = DATABASE_MYSQL;  // TiDB, MariaDB, OceanBase compatible
DEFAULT_SCHEMA = "sys";

MySQL version and JDBC URI from `DemoSQLConfig.java:214,279`:

public String gainDBVersion() {
    if (isMySQL()) {
        return "8.0.11"; // MYSQL 8 和 7 使用的 JDBC 配置不一样
    }
    // ...
}

public String gainDBUri() {
    if (isMySQL()) {
        return "jdbc:mysql://localhost:3306?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8";
    }
    // ...
}

Druid datasource configuration from `application.yml:33-53`:

spring:
  datasource:
    druid:
      driverClassName: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
      username: root
      password: apijson
      initialSize: 5
      maxActive: 20
      poolPreparedStatements: true

Common Errors

Error Message Cause Solution
`Access denied for user 'root'@'localhost'` Default credentials not matching local MySQL Update `gainDBAccount()` and `gainDBPassword()` in `DemoSQLConfig.java`
` Communications link failure` MySQL not running or wrong port Ensure MySQL is on `localhost:3306`
`Unknown database 'sys'` Schema not created Run `CREATE DATABASE sys;` in MySQL
`MySQL 8 vs 7 JDBC config mismatch` Different JDBC URL format per version Update `gainDBUri()` — MySQL 8.0+ needs `userSSL=false`

Compatibility Notes

  • MySQL 8.0+: The demo defaults to MySQL 8.0.11. MySQL 5.7 uses a different JDBC URL format.
  • TiDB / MariaDB / OceanBase: Treated as MySQL-compatible. TiDB default port is 4000.
  • PostgreSQL: Supported via HikariCP datasource. PostgreSQL JDBC requires catalog in URI (`?stringtype=unspecified`).
  • Multi-datasource: Three Druid beans are configured. Use `@datasource` keyword in APIJSON requests to select.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment