This repository contains the necessary files to build a Docker image based on the official mysql:8.4 image (Oracle Linux 9) that includes the MeCab Full-Text Parser Plugin. This allows for Japanese full-text searching capabilities within MySQL.
git clone https://github.com/stupidloud/mysql-with-mecab.git
cd mysql-with-mecab
docker build -t mysql-mecab:latest .
You can use this image like any other MySQL image. Here's an example using docker run:
docker run --name some-mysql-mecab -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql-mecab:latest
Or in a docker-compose.yml file:
services:
db:
image: mysql-mecab:latest # Use the locally built image or replace with your published image (e.g., your-dockerhub-username/mysql-mecab:latest)
container_name: mysql_with_mecab
environment:
MYSQL_ROOT_PASSWORD: your_root_password
MYSQL_DATABASE: your_database
MYSQL_USER: your_user
MYSQL_PASSWORD: your_password
volumes:
- ./mysql_data:/var/lib/mysql
ports:
- "3306:3306"
restart: always
When MySQL service starts, the MeCab plugin is automatically loaded (via the plugin-load-add configuration). You can verify the installation by connecting to the MySQL instance and running:
SHOW PLUGINS;
SHOW STATUS LIKE 'mecab_charset';
The default dictionary is the UTF-8 IPA dictionary (mecab-ipadic), so full-text indexed columns must use the utf8mb4 character set:
CREATE TABLE articles (
id INT PRIMARY KEY AUTO_INCREMENT,
body TEXT,
FULLTEXT (body) WITH PARSER mecab
) DEFAULT CHARSET=utf8mb4;
innodb_ft_min_token_size is set to 1 so that short Japanese words are indexed. If you change this value on an existing database, rebuild existing full-text indexes.
When the data directory is initialized for the first time, initdb/01-mecab-stopwords.sql creates the stopword table ft_stopwords.ja (InnoDB's default English stopwords plus Japanese particles and auxiliary verbs such as は, の, です, ます, plus full-width and ASCII punctuation/symbols such as 。, :, ・, ―, /) and enables it with SET PERSIST innodb_ft_server_stopword_table = 'ft_stopwords/ja'. Stopwords are ignored both when indexing and when searching, so documents no longer match just because they share a particle.
ft_stopwords.ja; changes only apply to full-text indexes created or rebuilt afterwards.On every push to main (or when triggered manually), the Docker Image CI workflow builds the image, pushes it to Docker Hub as kl3x/mysql-mecab:latest, and syncs this README to the Docker Hub description. It requires the DOCKERHUB_USERNAME and DOCKERHUB_TOKEN repository secrets.
Dockerfile: Defines the multi-stage build process for the image. The plugin is compiled from the MySQL source tag that exactly matches the mysqld version in the base image.mecab.cnf: MySQL configuration file that loads the MeCab plugin with plugin-load-add and sets innodb_ft_min_token_size=1.initdb/01-mecab-stopwords.sql: Creates and enables the Japanese stopword table on first initialization.Content type
Image
Digest
sha256:f8017eed6…
Size
246.5 MB
Last updated
9 days ago
docker pull kl3x/mysql-mecab