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'));
Errors
Common errors & fixes
MySQLStore is not a constructor
Using require('express-mysql-session') directly without calling it with express-session.
fixconst 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.
fixUse 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.
fixSwitch to mysql2 or alter MySQL user to use mysql_native_password.
Audit
Dependencies
express-sessionrequiredpeer dependency required to use the session store
mysqlrequiredruntime dependency for MySQL connection