展示 HN: VillageSQL = MySQL 和扩展
Show HN: VillageSQL = MySQL and Extensions

原始链接: https://github.com/villagesql/villagesql-server

## VillageSQL:面向代理AI时代的MySQL VillageSQL是一个开源创新平台,基于MySQL 8.4.6 LTS进行分支,旨在扩展MySQL在代理AI时代的能力。它引入了**VillageSQL扩展框架 (VEF)**,允许开发者在数据库内创建和加载自定义数据类型和函数,同时保持与现有MySQL 8.4应用程序的兼容性。 目前处于**Alpha**阶段,VillageSQL 仅供开发和测试使用,*不*用于生产环境。安装目前需要使用CMake、C++17编译器和其他依赖项从源代码构建(详细要求请参见[villagesql.com](villagesql.com))。 VEF 实现了诸如复数数据类型(通过`vsql_complex`扩展)等功能,并提供了一个C++ SDK用于构建高性能扩展。用户可以通过SQL命令管理扩展,包括安装、验证和卸载。 虽然此Alpha版本缺少自定义索引和Windows支持等功能,但VillageSQL 旨在成为一个强大且可扩展的数据库解决方案。欢迎通过GitHub Issues提交错误报告和功能请求,项目路线图可在[villagesql.com/roadmap](villagesql.com/roadmap)查看。

## VillageSQL:通过创新扩展MySQL VillageSQL 是一个全新的、开源的 MySQL 分支,旨在通过一个关键特性——**可扩展性**——重振其生态系统。与 MySQL 历史上严格的开发流程不同,VillageSQL 允许开发者通过扩展框架添加自定义数据类型和函数,这借鉴了 Postgres 和 GitHub 分支模型的成功经验。 该项目提供 MySQL 的即插即用替代品,并包含 AI、UUID 和密码学等领域的示例扩展。用户友好的 C++ API 简化了扩展的创建。 创建者强调了团队的数据库专业知识(包括前 Google BigTable/Colossus 技术负责人),并幽默地请求社区参与代码贡献 ([https://github.com/villagesql/villagesql-server](https://github.com/villagesql/villagesql-server))。一位评论员也指出,将 UUID 作为主键使用时可能存在性能方面的考虑。
相关文章

原文

VillageSQL Logo

License: GPL v2 Discord GitHub Release

VillageSQL is the innovation platform for MySQL and a new path for MySQL in the agentic AI era. VillageSQL Server is an open-source tracking fork of MySQL 8.4.6 LTS that introduces the VillageSQL Extension Framework (VEF).

VEF enables custom data types and functions while maintaining MySQL 8.4 compatibility.

Warning

Alpha Status: VillageSQL is currently in alpha. It is intended for development and testing purposes only and is not yet recommended for production use.

  • VillageSQL Extension Framework (VEF): Framework for building and loading extensions (.veb bundles).
  • Custom Data Types: Define and use domain-specific data types directly in your SQL schema.
  • Custom Functions: Implement high-performance logic within the database.
  • Drop-in Replacement: Compatible with existing MySQL 8.4 applications and tools.

📚 Full Documentation: Visit villagesql.com/docs for comprehensive guides on building extensions, architecture details, and more.

Installation (Building from Source)

During the alpha phase, VillageSQL must be built from source. Docker and pre-built binary installations are coming soon. VillageSQL follows the same build requirements as standard MySQL 8.4.

  • CMake (3.14.3 or higher)
  • C++17 Compiler (GCC 11+, Clang 13+, or MSVC 2019+)
  • OpenSSL 3.0+
  • Bison (3.0 or higher)
  • pkg-config
  • ncurses development libraries
  • libtirpc and rpcsvc-proto

Linux (Debian/Ubuntu):

sudo apt install cmake libssl-dev libncurses5-dev pkg-config bison \
                 libtirpc-dev rpcsvc-proto build-essential zlib1g-dev

macOS (Homebrew):

brew install cmake openssl@3 pkgconf bison libtirpc rpcsvc-proto

Build Steps (Linux & macOS)

Note: Linux users should use $HOME for paths. macOS users should use ~ (tilde) for paths.

  1. Clone the repository:

    git clone --depth 1 https://github.com/villagesql/villagesql-server.git
    cd villagesql-server
  2. Create a build directory (outside the repository):

    Linux:

    mkdir -p $HOME/build/villagesql
    cd $HOME/build/villagesql

    macOS:

    mkdir -p ~/build/villagesql
    cd ~/build/villagesql
  3. Configure with CMake:

    Linux:

    # Standard build
    cmake $HOME/villagesql-server -DWITH_SSL=system
    
    # Or for a debug build (recommended for development)
    cmake $HOME/villagesql-server -DWITH_DEBUG=1 -DWITH_SSL=system

    macOS:

    # Standard build
    cmake ~/villagesql-server -DWITH_SSL=system
    
    # Or for a debug build (recommended for development)
    cmake ~/villagesql-server -DWITH_DEBUG=1 -DWITH_SSL=system
  4. Build:

    make -j $(($(getconf _NPROCESSORS_ONLN) - 2))
  5. Initialize and Start the Server:

    Linux:

    # Create the data directory
    mkdir -p $HOME/mysql-data/data
    
    # Initialize the data directory (insecure mode for development)
    bin/mysqld --initialize-insecure --datadir=$HOME/mysql-data/data --basedir=$HOME/build/villagesql
    
    # Start the server (runs in foreground, use Ctrl-C to stop)
    bin/mysqld --gdb --datadir=$HOME/mysql-data/data --basedir=$HOME/build/villagesql
    
    # In a new terminal, connect using the client
    $HOME/build/villagesql/bin/mysql -u root
    
    # Verify the installation
    $HOME/build/villagesql/bin/mysql -u root -e "SELECT VERSION()"

    Running as root (Docker or sudo):

    If running as root (e.g., in Docker), MySQL requires the --user=root flag:

    # Initialize as root
    bin/mysqld --user=root --initialize-insecure --datadir=$HOME/mysql-data/data --basedir=$HOME/build/villagesql
    
    # Start as root
    bin/mysqld --user=root --gdb --datadir=$HOME/mysql-data/data --basedir=$HOME/build/villagesql

    macOS:

    # Create the data directory
    mkdir -p ~/mysql-data/data
    
    # Initialize the data directory (insecure mode for development)
    bin/mysqld --initialize-insecure --datadir=~/mysql-data/data --basedir=~/build/villagesql
    
    # Start the server (runs in foreground, use Ctrl-C to stop)
    bin/mysqld --gdb --datadir=~/mysql-data/data --basedir=~/build/villagesql
    
    # In a new terminal, connect using the client
    ~/build/villagesql/bin/mysql -u root
    
    # Verify the installation
    ~/build/villagesql/bin/mysql -u root -e "SELECT VERSION()"

    Note: --initialize-insecure creates a root user with no password for development. The --gdb flag installs a signal handler that allows you to Ctrl-C to quit the server. For production, use --initialize instead (generates a temporary password) and refer to MySQL 8.4 initialization documentation for secure setup.

    Setting up users and permissions:

    -- Create a new user
    CREATE USER myuser IDENTIFIED BY 'password';
    
    -- Grant permissions
    GRANT ALL PRIVILEGES ON *.* TO myuser;

    Verify the new user:

    Linux:

    $HOME/build/villagesql/bin/mysql -u myuser -p -e "SELECT USER()"

    macOS:

    ~/build/villagesql/bin/mysql -u myuser -p -e "SELECT USER()"

Verify your build with the test suite:

Linux:

# From your build directory
cd $HOME/build/villagesql

# Run all VillageSQL tests including sub-suites
mysql-test/mysql-test-run.pl --do-suite=villagesql --parallel=auto

# Run a specific test
mysql-test/mysql-test-run.pl villagesql.my_test_name

# Update test results after making changes
mysql-test/mysql-test-run.pl --record villagesql.my_test_name

# Run VillageSQL unit tests
make -j $(($(getconf _NPROCESSORS_ONLN) - 2)) villagesql-unit-tests && ctest -L villagesql

macOS:

# From your build directory
cd ~/build/villagesql

# Run all VillageSQL tests including sub-suites
mysql-test/mysql-test-run.pl --do-suite=villagesql --parallel=auto

# Run a specific test
mysql-test/mysql-test-run.pl villagesql.my_test_name

# Update test results after making changes
mysql-test/mysql-test-run.pl --record villagesql.my_test_name

# Run VillageSQL unit tests
make -j $(($(getconf _NPROCESSORS_ONLN) - 2)) villagesql-unit-tests && ctest -L villagesql

Quick Start: Using Extensions

When building from source, VillageSQL Server includes two built-in extensions:

  • vsql_complex: Complex number data type and arithmetic
  • vsql_simple: A minimal "Hello World" demonstration of custom types and functions

Note

Additional extensions are available in separate repositories:

These can be built from their repositories and installed by copying the .veb files to your VEF directory.

Once the server is running, you can manage extensions using new SQL commands:

-- Install an extension bundle (e.g., vsql_complex)
INSTALL EXTENSION vsql_complex;

-- Verify the extension is loaded
SELECT extension_name, extension_version
FROM INFORMATION_SCHEMA.EXTENSIONS;

-- Create a database and use it
CREATE DATABASE demo;
USE demo;

-- Use a custom type provided by an extension
CREATE TABLE signals (
  id INT PRIMARY KEY,
  reading COMPLEX -- Example type from vsql_complex
);

-- Insert sample data
INSERT INTO signals VALUES (1, '(3,4)'), (2, '(5,12)'), (3, '(-1,2)');

-- Query using custom functions (note: functions require extension prefix)
SELECT
  id,
  reading,
  vsql_complex.complex_abs(reading) AS magnitude,
  vsql_complex.complex_real(reading) AS real_part,
  vsql_complex.complex_imag(reading) AS imag_part
FROM signals;

-- Clean up: Drop table first, then uninstall extension
DROP TABLE signals;
UNINSTALL EXTENSION vsql_complex;

VillageSQL provides a C++ SDK for building high-performance extensions.

  • Example Code:
    • villagesql/examples/vsql-complex: Reference implementation with arithmetic, custom hash handlers, and platform-independent serialization.
    • villagesql/examples/vsql-simple: A minimal "Hello World" implementation of a custom type and functions.
  • Header API: Detailed extension API definitions can be found in villagesql/include/villagesql/extension.h.
  • Source-only Build: No official Docker images or binary packages are available yet.
  • No Custom Indexes: Custom data types cannot be indexed in this version (coming soon).
  • Alpha Stability: Expect breaking changes and potential bugs as we progress towards Beta.
  • No Windows Support: We don't support compiling to .dll to Windows yet. (#16)

Priority items are listed below. The full roadmap can be found at villagesql.com/roadmap.

OpenSSL not found:

# macOS with Homebrew
brew install openssl@3
cmake ~/villagesql-server -DWITH_SSL=/opt/homebrew/opt/openssl@3

# Linux (Ubuntu/Debian)
sudo apt-get install libssl-dev
cmake ~/villagesql-server -DWITH_SSL=system

Bison version too old:

# macOS
brew install bison
export PATH="/opt/homebrew/opt/bison/bin:$PATH"

# Linux
sudo apt-get install bison

Can't connect to server:

  • Check that mysqld is running: pgrep -a mysqld or ps aux | grep mysqld
  • Verify socket path matches between server and client
  • Check error log in your data directory (e.g., ~/mysql-data/data/*.err)

Port already in use: If you see "Bind on TCP/IP port: Address already in use", either stop the existing MySQL instance or specify a different port:

bin/mysqld --gdb --datadir=~/mysql-data/data --basedir=~/build/villagesql --port=3307

For more help, visit our Discord community or file an issue.

Reporting Bugs and Requesting Features

If you encounter a bug or have a feature request, please open an issue using GitHub Issues. Please provide:

  • A clear title and detailed description.
  • Steps to reproduce (if applicable).
  • Environment details (OS, compiler, OpenSSL version).

We welcome contributions. Please see CONTRIBUTING.md for guidelines on how to get involved.

VillageSQL Server is licensed under the GPLv2 (the same as MySQL).

联系我们 contact @ memedata.com