Registry / database / connect-mysql2

connect-mysql2

JSON →
library2.2.6jsnpmunverified

connect-mysql2 is a MySQL-backed session store for Express/Connect applications, version 2.2.6. It uses the mysql2 driver and provides features like connection pooling, session encryption, keepalive, and automatic cleanup. Its release cadence is low; it is actively maintained. Compared to alternatives like connect-mysql (which uses the older mysql driver), it benefits from the mysql2 performance and promise support. Not intended for use with MySQL 2.x, but rather with the mysql2 npm package. Sessions from earlier versions are not backwards-compatible with v2.2.

npm install connect-mysql2
INSTALL
IMPORT
SIG · CONNECT-MYSQL2
C
connect-mysql2
databasejavascriptv2.2.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MySQLStore
const MySQLStore = require('connect-mysql2')(session);
import MySQLStore from 'connect-mysql2';
CommonJS only; ESM import not supported. Must pass session middleware to factory function.

Sets up an Express app with MySQL-backed session storage using connect-mysql2, showing basic configuration and usage.

const express = require('express'); const session = require('express-session'); const MySQLStore = require('connect-mysql2')(session); const app = express(); app.use(session({ secret: 'keyboard cat', resave: false, saveUninitialized: true, store: new MySQLStore({ config: { user: process.env.DB_USER || 'root', password: process.env.DB_PASSWORD || '', database: process.env.DB_NAME || 'test' } }) })); app.get('/', (req, res) => { if (req.session.views) { req.session.views++; } else { req.session.views = 1; } res.send('Views: ' + req.session.views); }); app.listen(3000);
Debug
Known issues
breakingSessions stored with v2.1 are not compatible with v2.2 and must be cleared.
fix
Clear the sessions table before upgrading to v2.2, or expect warnings.
affects: >=2.2
Errors
Common errors & fixes
TypeError: MySQLStore is not a constructor
Using require('connect-mysql2') directly without passing session middleware to the factory function.
fix
Use const MySQLStore = require('connect-mysql2')(session);
Error: Cannot find module 'mysql2'
mysql2 package is not installed as a dependency.
fix
Run `npm install mysql2` in your project.
Upgrade
Version history
2.2.6latest on npm
Audit
Dependencies
express-sessionrequiredPeer dependency for session middleware integration
mysql2requiredRequired for MySQL database connections
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
connect-mysql2 — npm install connect-mysql2 · libregistry