
mysql2
fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS
About
fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS
Live mirror of the GitHub README. Updated whenever the repo's default branch changes.
MySQL2
English | 简体中文 | Português (BR)
MySQL client for Node.js with focus on performance. Supports prepared statements, non-utf8 encodings, binary log protocol, compression, ssl much more.
Table of Contents
History and Why MySQL2
MySQL2 project is a continuation of MySQL-Native. Protocol parser code was rewritten from scratch and api changed to match popular Node MySQL. MySQL2 team is working together with Node MySQL team to factor out shared code and move it under mysqljs organization.
MySQL2 is mostly API compatible with Node MySQL and supports majority of features. MySQL2 also offers these additional features:
- Faster / Better Performance
- Prepared Statements
- MySQL Binary Log Protocol
- MySQL Server
- Extended support for Encoding and Collation
- Promise Wrapper
- Compression
- SSL and Authentication Switch
- Custom Streams
- Pooling
Installation
MySQL2 is free from native bindings and can be installed on Linux, Mac OS or Windows without any issues.
npm install --save mysql2
If you are using TypeScript, you will need to install @types/node.
npm install --save-dev @types/node
For TypeScript documentation and examples, see here.
Documentation
Acknowledgements
- Internal protocol is written by @sidorares MySQL-Native.
- Constants, SQL parameters interpolation, Pooling,
ConnectionConfigclass taken from Node MySQL. - SSL upgrade code based on @TooTallNate code.
- Secure connection / compressed connection api flags compatible to MariaSQL client.
- Contributors.
Contributing
Want to improve something in MySQL2? Please check Contributing.md for detailed instruction on how to get started.
To contribute in MySQL2 Documentation, please visit the Website Contributing Guidelines for detailed instruction on how to get started.
Quick facts
npm install mysql2Common pairings
Packages this one expects to find in the same project. Each is also a Sourcemap Explorer detection target.
How Sourcemap Explorer detects mysql2
We catch mysql2 from two complementary signals: bundled source paths and the embedded package.json. Modern bundlers (webpack, Vite, esbuild, Rollup, Turbopack) preserve the original node_modules/mysql2/ paths inside the JavaScript sourcemap's sources[] array — that's the canonical signal. When the matching package.json is also captured in sourcesContent[], we read the exact version field — patch number included. No regex guessing, no version inference.
- 1
Confirm the site exposes sourcemaps
In DevTools Network, check the response headers of any application script for `SourceMap` or `X-SourceMap`. Failing that, fetch the script's last 4 KB and look for a `//# sourceMappingURL=` comment.
- 2
Find the package in the bundle
Open DevTools → Network → reload. Click any application script and look at its sourcemap. Inside, search `sources[]` for entries matching `node_modules/mysql2/` — every match confirms the package is bundled. The matching `sourcesContent[i]` for `node_modules/mysql2/package.json` gives you the exact installed version.
- 3
Read the version directly from package.json
Run `jq -r '. as $m | $m.sources | to_entries[] | select(.value | endswith("node_modules/mysql2/package.json")) | $m.sourcesContent[.key] | fromjson | .version' bundle.js.map`. Sourcemap Explorer automates the same query in the popup.
Recent versions
FAQ
What is mysql2 used for?
fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS
How can I tell if a website is using mysql2?
Open the page in Chrome with the Sourcemap Explorer extension installed and read the Stack tab. We catch `mysql2` from two complementary signals: `node_modules/mysql2/` paths inside the JavaScript sourcemap, and the embedded `package.json` we read for exact-version detection. Without the extension you can do the same lookup manually in DevTools — the steps are listed in the "How Sourcemap Explorer detects" section above.
What is the latest version of mysql2?
3.22.3, as published on the npm registry. The "Recent versions" table on this page lists the most recent 8 releases with their release dates. Sourcemap Explorer reports the version actually bundled into a site, which can lag the latest release by months on real-world deployments.
Where can I read more?
Project homepage: https://sidorares.github.io/node-mysql2/docs. Source code: https://github.com/sidorares/node-mysql2. Published on npm: https://www.npmjs.com/package/mysql2. Licensed as MIT.
Detected by Sourcemap Explorer
When a bundle ships sourcemaps, we read the embedded package.json for mysql2 and report the precise version. Without sourcemaps, an import / require in the page's scripts is enough to flag it.