Registry / storage / express-mysql2-session

express-mysql2-session

JSON →
library1.0.1jsnpmunverified

A MySQL session store for express.js, version 1.0.1. This package provides a session store implementation backed by MySQL, designed to work with the express-session middleware. It uses the mysql npm package internally but also supports passing an existing connection or pool. The store creates a session table automatically and supports custom table schemas. It is actively maintained and ships TypeScript type definitions.

npm install express-mysql2-session
INSTALL
IMPORT
SIG · EXPRESS-MYSQL2-SES
E
express-mysql2-session
storagejavascriptv1.0.1
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('express-mysql-session')(session);
const { MySQLStore } = require('express-mysql-session');
The package exports a function that must be called with the express-session object.
MySQLStore
import session from 'express-session'; import MySQLStore from 'express-mysql-session'; const store = MySQLStore(session);
import { MySQLStore } from 'express-mysql-session';
TypeScript ESM import requires calling the default export with express-session.
MySQLStore
const MySQLStore = require('express-mysql-session')(require('express-session'));
const MySQLStore = require('express-mysql-session');
You must pass the session constructor to the required function.

Basic setup of express-mysql-session with express-session, creating a session store with MySQL connection options.

const express = require('express'); const session = require('express-session'); const MySQLStore = require('express-mysql-session')(session); const app = express(); const options = { host: process.env.MYSQL_HOST ?? 'localhost', port: parseInt(process.env.MYSQL_PORT ?? '3306'), user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', database: process.env.MYSQL_DATABASE ?? 'test' }; const sessionStore = new MySQLStore(options); app.use(session({ secret: 'secret', store: sessionStore, resave: false, saveUninitialized: false })); 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, () => console.log('Server running on port 3000'));
Debug
Known issues
breakingConstructor signature changed in v1.0.0: the session argument is now a function call, not a constructor.
fix
Wrap the import: const MySQLStore = require('express-mysql-session')(session);
affects: >=0.0.0 <1.0.0
deprecatedThe mysql npm package is no longer maintained. It is recommended to use mysql2 if possible.
fix
Use mysql2 by passing an existing connection/pool or provide mysql2 driver manually.
affects: >=0.0.0
gotchaThe session table is created with utf8mb4 collation, which requires MySQL 5.5.3+. Older MySQL versions will fail to create the table automatically.
fix
Create the sessions table manually with a compatible collation before initializing the store.
affects: >=0.0.0
Errors
Common errors & fixes
MySQLStore is not a constructor
Using require('express-mysql-session') directly without calling it with express-session.
fix
const MySQLStore = require('express-mysql-session')(session);
Client does not support authentication protocol requested by server; consider upgrading MySQL client
The mysql npm package uses old authentication protocol. MySQL 8+ uses caching_sha2_password by default.
fix
Use mysql2 with ALTER USER or set default_authentication_plugin=mysql_native_password.
ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol
Same as above, common with mysql package.
fix
Switch to mysql2 or alter MySQL user to use mysql_native_password.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
express-sessionrequiredpeer dependency required to use the session store
mysqlrequiredruntime dependency for MySQL connection
Agent activity
17 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
express-mysql2-session — npm install express-mysql2-session · libregistry