# Is mysql2 ESM-only? Can you require() it?

> mysql2@3.24.4 is a CommonJS package. CommonJS — require() works on every Node.js version we test.

fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS

Last verified Sep 9, 2026 against mysql2@3.24.4.

mysql2 ships CommonJS only. require("mysql2") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >= 8.0. import "mysql2" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

## What to do

1. require("mysql2") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >= 8.0.
2. From ES modules use the default import: import mysql2 from "mysql2"; then destructure. Named imports only work when Node.js can statically detect the exports.
3. TypeScript: types are bundled; install nothing extra.

## Facts

- Latest: 3.24.4 (Sep 8, 2026)
- Module format: CommonJS
- Last CommonJS version: 3.24.4
- TypeScript types: bundled
- Node engines: >= 8.0
- Weekly downloads: 10.5M
- License: MIT

## Runtime test results for mysql2@3.24.4

Installed and executed on Sep 9, 2026 with require("mysql2") from a CommonJS file and import "mysql2" from an ES module.

| Runtime | require("mysql2") | import "mysql2" |
|---|---|---|
| Node.js 18 | works | works |
| Node.js 20 | works | works |
| Node.js 22 | works | works |
| Node.js 24 | works | works |
| Node.js 26 | works | works |
| Bun 1.4.0 | works | works |

## How to import mysql2

ES modules:

```js
import mysql2 from "mysql2";
```

CommonJS:

```js
const mysql2 = require("mysql2");
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (216 versions; the newest 60 shown).

| Versions | Format | First published |
|---|---|---|
| 3.9.7 – 3.24.4 | CommonJS | Apr 21, 2024 |

## Frequently asked

**Is mysql2 ESM-only?**

mysql2@3.24.4 is a CommonJS package. mysql2 ships CommonJS only. require("mysql2") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >= 8.0. import "mysql2" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

**Can I import mysql2 with ES module syntax?**

Yes. import mysql2 from "mysql2" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

**Does mysql2 work in Bun?**

Yes. import "mysql2" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

**Does mysql2 ship TypeScript types?**

Yes. mysql2 bundles its own type declarations; no @types package is needed.

## Links

- [mysql2 on npm](https://www.npmjs.com/package/mysql2)
- [Source repository](https://github.com/sidorares/node-mysql2)
- [HTML version](https://canirequire.com/package/mysql2/)
- [JSON version](https://canirequire.com/package/mysql2.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
