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 module is a function that must be called with express-session as argument. Common mistake: forgetting to pass session.
MySQLStore (TypeScript)
✓ import session from 'express-session';
import mysqlSession from 'express-mysql-session';
const MySQLStore = mysqlSession(session);
✗ import MySQLStore from 'express-mysql-session';
Default import is not the store itself; you must pass session to the default export.
MySQLStore (with existing connection)
✓ const MySQLStore = require('express-mysql-session')(session);
const sessionStore = new MySQLStore({}, existingConnection);
✗ const sessionStore = new MySQLStore({}, connection); // missing (session) call
Always call the export with session first, even when providing an existing connection.
Basic setup of express-session with MySQL session store using default options.
const express = require('express');
const session = require('express-session');
const MySQLStore = require('express-mysql-session')(session);
const app = express();
const options = {
host: 'localhost',
port: 3306,
user: 'session_test',
password: process.env.MYSQL_PASSWORD || '',
database: 'session_test'
};
const sessionStore = new MySQLStore(options);
app.use(session({
key: 'session_cookie_name',
secret: 'session_cookie_secret',
store: sessionStore,
resave: false,
saveUninitialized: false
}));
app.get('/', (req, res) => {
res.send('Session store ready');
});
app.listen(3000, () => console.log('Server listening on port 3000'));
Errors
Common errors & fixes
TypeError: MySQLStore is not a constructor
The module export was not called with express-session as argument.
fixconst MySQLStore = require('express-mysql-session')(session); // note (session) Error: The mysql driver used does not support prepared statements
Using the old 'mysql' package instead of 'mysql2'.
fixnpm install mysql2 and replace require('mysql') with require('mysql2'). ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value
Session data contains characters not supported by utf8mb4 collation.
fixEnsure session data is valid UTF-8 or use a different collation for the 'data' column.
Audit
Dependencies
express-sessionrequiredpeer dependency; store is designed to be used with express-session middleware
mysql2requiredruntime dependency for MySQL connection; the library wraps mysql2 internally