OSS Tanbou

connect Ruby to MySQL or MariaDB and handle SQL queries, prepared statements, and streaming results

About these scores

OSS scale score is an unbounded metric that log-compresses and weights Stars, Watchers, Forks, and Contributors. Discovery score is the current OSS scale score minus the score at discovery. Update pace is commits in the last 30 days, growth momentum is the OSS scale score difference within the recent observation window, and OSS health is a 0–100 rating based on available recency, Community Health, and release data.

Stars
2,276
Primary language
Ruby
License
MIT
Repository last updated
Sep 9, 2026
On this page

Overview

mysql2 is a native-extension Ruby gem for connecting to MySQL-compatible servers. Mysql2::Client, Mysql2::Result, and Mysql2::Statement cover connections, queries, prepared statements, and result iteration. The extension links against MySQL libmysqlclient, Connector/C, or compatible clients such as MariaDB.

Features and best fit

Based on official documentation; not hands-on tested · Content checked:

Key features

Handle connections, queries, and prepared statements through a small API

Mysql2::Client represents a connection, Mysql2::Result represents query output, and Mysql2::Statement represents a prepared statement, avoiding a direct one-to-one exposure of the underlying C API.

Sources: [1]

Configure UTF-8, TLS, and connection options through the client library

Connections use UTF-8 or binary and can configure TLS modes, MySQL option files, sockets, hosts, and other client settings. Available TLS behavior also depends on the linked MySQL or MariaDB client library and server.

Sources: [1]

Stream large results and use asynchronous queries where appropriate

:stream => true can fetch rows on demand, while :async => true sends a query so the application can monitor socket readiness before collecting the result.

Sources: [1]

Best fit

Fits Rails and Ruby applications backed by MySQL-compatible databases

Active Record can use mysql2 as its adapter, while plain Ruby applications can use the Client API directly for MySQL or MariaDB database access.

Sources: [1]

Before adoption

Native builds require a compatible client library and headers

Installation links against MySQL libmysqlclient, Connector/C, or a compatible implementation such as MariaDB. Platform development packages such as libmysqlclient-dev or libmariadb-dev may be required.

Sources: [1]

Account for streaming and asynchronous-query limits

A streaming result must be fully consumed before another query uses the same connection. The README also notes that asynchronous queries are not supported on Windows, so concurrency design may require connection pooling.

Sources: [1]

Pin both the stable gem and native dependencies

As of October 3, 2026, the latest stable release is 0.5.7, and its gemspec requires Ruby 2.0 or later. Validate the MySQL or MariaDB client library and OpenSSL combination used for both build and runtime.

Sources: [3][2][1]

Official sources

  1. [1]mysql2 0.5.7 README(2026-10-03)
  2. [2]mysql2 0.5.7 gemspec(2026-10-03)
  3. [3]mysql2 0.5.7 release(2026-10-03)
  4. [4]mysql2 MIT license(2026-10-03)
Supplemental curator note

Compatibility spans both the Ruby API and the MySQL or MariaDB client library used at build and runtime. Pin development headers and runtime libraries consistently in containers and CI to keep native-extension builds reproducible.

Try it in 3 steps

  1. 1

    Install mysql2 0.5.7

    Build the pinned stable release in an environment with compatible MySQL or MariaDB client libraries and development headers.

    gem install mysql2 -v 0.5.7
  2. 2

    Load the native extension and verify the version

    Confirm the gem and native extension load successfully without connecting to a database.

    ruby -rmysql2 -e 'puts Mysql2::VERSION'
  3. 3

    Inspect the default query options

    Load the Client API and inspect defaults such as :async, :as, and :symbolize_keys. Configure host, credentials, and TLS for the actual environment.

    ruby -rmysql2 -e 'p Mysql2::Client.default_query_options'
Check the official README

Growth

Growth trends · Last 30 days

2,276 Stars

Trend data is still being collected.

Development activity

Last 90 days · weekly

Commits (last 30 days)
1
Open PRs
33

Development activity is still being collected.

Built with

Categories and tags

GitHub data

GitHub dataView detailed GitHub data
Stars
2,276
Forks
563
Watchers
67
Open issues
45
Contributors
146
Owner type
User
Primary language
Ruby
License
MIT
Repository last updated
Sep 9, 2026
Write a related article

Share a guide or use case for this OSS in Markdown. Articles are published after administrator approval.

Report incorrect information

Tell us if any listing information is incorrect or outdated.

After reading this page, do you know what to do next?