Skip to content
In-memory search engine

MygramDBFast full-text search for MySQL

An in-memory index that follows the MySQL / MariaDB binlog. Writes stay in MySQL; search moves to MygramDB.

MIT licensedSingle binaryMySQL & MariaDBv1.14.0
SEARCH LATENCY"quantum physics"
MySQL FULLTEXT653ms
MygramDBin-memory1.90ms
343× on this query · 14.9× median across all · p50 on 1,100,000 docs

How it fits ​

MygramDB runs as a sidecar next to MySQL or MariaDB. Your application keeps writing to the database as before. MygramDB follows the binlog into its own in-memory index, and only search queries go to MygramDB.

Quick Start ​

Prepare MySQL ​

Turn on GTID mode and create a replication user. MygramDB reads the binlog (MySQL's change log) and uses GTIDs to track how far it has read; see the Glossary.

sql
SET GLOBAL enforce_gtid_consistency = ON;
SET GLOBAL gtid_mode = OFF_PERMISSIVE;
SET GLOBAL gtid_mode = ON_PERMISSIVE;
SET GLOBAL gtid_mode = ON;
SET GLOBAL binlog_format = ROW;
SET GLOBAL binlog_row_image = FULL;
SET GLOBAL binlog_row_metadata = FULL;
CREATE USER 'repl_user'@'%' IDENTIFIED BY 'your_password';
-- SELECT: for initial snapshot of search target tables
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repl_user'@'%';
GRANT SELECT ON mydb.* TO 'repl_user'@'%';

Persist the settings

SET GLOBAL values can reset on restart. In production, keep log_bin on and also set gtid_mode=ON, binlog_format=ROW, binlog_row_image=FULL and binlog_row_metadata=FULL in my.cnf or your managed parameter group. Upgrading an existing deployment? Follow the upgrade checklist first.

Start MygramDB ​

bash
export API_ADMIN_TOKEN="$(openssl rand -hex 32)"
docker run -d --name mygramdb \
  -p 127.0.0.1:11016:11016 -p 127.0.0.1:8080:8080 \
  -e API_BIND=0.0.0.0 -e API_HTTP_BIND=0.0.0.0 \
  -e API_ADMIN_TOKEN \
  -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 TABLE_PRIMARY_KEY=id \
  -e TABLE_TEXT_COLUMN=content \
  -e TABLE_NGRAM_SIZE=2 \
  -e REPLICATION_SERVER_ID=12345 \
  -e NETWORK_ALLOW_CIDRS=127.0.0.1/32,::1/128,172.16.0.0/12 \
  ghcr.io/libraz/mygram-db:1.14.0

Network allowlist

Set NETWORK_ALLOW_CIDRS to the subnet MygramDB actually sees clients from; 172.16.0.0/12 is a local Docker bridge example. Keep the loopback entries for in-container clients and health checks. A 0.0.0.0/0 allowlist with a non-loopback container listener is rejected. See Docker deployment.

MygramDB does not import existing rows on startup. Run SYNC once to build the index from MySQL, check SYNC STATUS, then search.

bash
docker exec -it mygramdb mygram-cli
mygram
AUTH <API_ADMIN_TOKEN>
SYNC articles
SYNC STATUS
SEARCH articles hello world

Client Libraries ​

Official clients for Node.js, Go and Python. The client guide covers connection options, filters and error handling.

Node.jsnpm install mygramdb-clientnode-mygramdb-client
Gogo get github.com/libraz/go-mygram-clientgo-mygram-client
Pythonpip install mygramdb-clientpython-mygramdb-client
javascript
import { createMygramClient } from 'mygramdb-client'

const client = createMygramClient({ host: 'localhost', port: 11016 })
await client.connect()

const results = await client.search('app_db.articles', 'hello world', {
  limit: 10
})
go
import mygram "github.com/libraz/go-mygram-client"

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

resp, _ := client.Search("app_db.articles", "hello world", mygram.SearchOptions{
    Limit: 10,
})
python
from mygramdb_client import MygramClient, ClientConfig, SearchOptions

async with MygramClient(ClientConfig(host='localhost', port=11016)) as client:
    results = await client.search(
        'app_db.articles',
        'hello world',
        SearchOptions(limit=10),
    )
libmybinlogGitHub

The C++17 binlog decoder under MygramDB. Turns MySQL and MariaDB binlog bytes into typed events and row values, including checksums, GTIDs and compressed events. No network code.

binlogC++17MySQLMariaDB
mysql-event-streamGitHub

A lightweight MySQL / MariaDB CDC engine extracted from MygramDB. Streams decoded binlog events to applications through Node.js (N-API) and Python (ctypes) bindings. MySQL 8.4+ and MariaDB 10.11+.

CDCbinlogNode.jsPython