A modern, simple, and very fast MySQL client library for Ruby that binds to libmysql.
Mysql2 is a Ruby gem that serves as a high-performance client library for MySQL and MariaDB databases. It provides a clean, modern API for connecting, querying, and iterating over results, with efficient C bindings to libmysqlclient for fast data type casting. The gem solves the need for a simple yet powerful database interface in Ruby applications, avoiding the complexity of raw C APIs.
Ruby developers building applications that interact with MySQL or MariaDB databases, especially those using frameworks like Rails (Active Record) or Sequel. It's ideal for projects requiring performance, async capabilities, or advanced features like prepared statements and streaming results.
Developers choose Mysql2 for its blend of speed, simplicity, and reliability. It outperforms alternatives with C-level optimizations, offers a intuitive Ruby API, and supports modern features like async queries and encoding handling, making it the go-to MySQL library for the Ruby ecosystem.
A modern, simple and very fast Mysql library for Ruby - binding to libmysql
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses libmysqlclient for fast data type casting and iteration, significantly outperforming pure Ruby libraries in benchmarks, as shown in the README's performance comparison.
Offers simple classes like Client and Result that abstract away low-level details, making database operations straightforward with options for symbolized keys and array results.
Supports async queries with EventMachine, streaming for large datasets, prepared statements, and encoding handling, catering to advanced use cases outlined in the documentation.
Works out-of-the-box with Rails' Active Record and Sequel, reducing boilerplate code, as evidenced by configuration examples for database.yml and DATABASE_URL.
Requires platform-specific setup of libmysqlclient and OpenSSL, with detailed instructions needed for macOS and Windows, including handling OpenSSL conflicts on newer macOS versions.
Asynchronous functionality is not available on Windows, and some features like prepared statements reference known MySQL limitations that can affect edge cases.
The need for C libraries adds deployment complexity and potential compatibility issues in containerized or serverless environments, unlike pure-Ruby gems.