Skip to content

MygramDBサブミリ秒の全文検索

MySQL / MariaDB binlogレプリケーションで同期するインメモリ検索エンジン

クイックスタート

MySQLでGTIDモードとレプリケーションユーザーを設定:

sql
SET GLOBAL gtid_mode = ON;
CREATE USER 'repl_user'@'%' IDENTIFIED BY 'your_password';
-- SELECT: 全文検索対象テーブルの初期スナップショット取得用
GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON mydb.* TO 'repl_user'@'%';
bash
docker run -d --name mygramdb \
  -p 11016:11016 -p 8080:8080 \
  -e MYSQL_HOST=your-mysql-host \
  -e MYSQL_USER=repl_user \
  -e MYSQL_PASSWORD=your_password \
  -e MYSQL_DATABASE=mydb \
  -e TABLE_NAME=articles \
  -e NETWORK_ALLOW_CIDRS=0.0.0.0/0 \
  ghcr.io/libraz/mygram-db:latest

WARNING

NETWORK_ALLOW_CIDRS=0.0.0.0/0 はすべてのIPからの接続を許可します。本番環境では特定の範囲に制限してください(例: 10.0.0.0/8,172.16.0.0/12)。

bash
echo "SEARCH articles hello world" | nc localhost 11016

クライアントライブラリ

Node.js v1.6 compatible

bash
npm install mygramdb-client
bash
yarn add mygramdb-client
bash
bun add mygramdb-client
javascript
import { MygramClient } from 'mygramdb-client'

const client = new MygramClient({ host: 'localhost', port: 11016 })
const results = await client.search('articles', 'hello world')

mygramdb-client on GitHub

Go v1.6 compatible

bash
go get github.com/libraz/go-mygram-client
go
import mygram "github.com/libraz/go-mygram-client"

client := mygram.NewClient("localhost:11016")
defer client.Close()
client.Connect()

resp, _ := client.Search("articles", "hello world", mygram.SearchOptions{})

go-mygram-client on GitHub

Python v1.6 compatible

bash
pip install mygramdb-client
python
from mygramdb_client import MygramClient, ClientConfig

client = MygramClient(ClientConfig(host='localhost', port=11016))
await client.connect()

results = await client.search('articles', 'hello world')

python-mygramdb-client on GitHub

関連プロジェクト

mysql-event-stream

MygramDBから抽出した軽量なMySQL / MariaDB CDC (Change Data Capture) エンジン。binlogレプリケーションイベントをパースし、アプリケーション向けのストリーミングAPIを提供します。MySQL 8.4/9.x(VECTOR型、RSA認証)およびMariaDB 10.11+/11.x(サーバー種別の自動判定、domain-server-seq 形式のGTID、ANNOTATE_ROWS)に対応。Node.js (N-API) とPython (ctypes) バインディングに対応。

mysql-event-stream on GitHub