Registry / database / connect-mysql-store

connect-mysql-store

JSON →
library0.2.0jsnpmunverified

A simple and minimal MySQL session store for Express session middleware. Current stable version is 0.2.0. Release cadence is low; no recent updates. Key differentiators: minimal configuration, relies on MySQL connection string, and requires a predefined table schema. Suitable for small Express apps needing MySQL-backed sessions without complex ORM integration.

npm install connect-mysql-store
INSTALL
IMPORT
SIG · CONNECT-MYSQL-STOR
C
connect-mysql-store
databasejavascriptv0.2.0
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.

default
const MySQLStore = require('connect-mysql-store');
import MySQLStore from 'connect-mysql-store';
This package does not provide a default ESM export; use CommonJS require.
MySQLStore
const MySQLStore = require('connect-mysql-store');
const { MySQLStore } = require('connect-mysql-store');
The module exports a single constructor function directly, not as a named export.
session
const session = require('express-session');
const MySQLStore = require('connect-mysql-store'); const session = MySQLStore.session;
session must be imported separately from express-session, not from this package.

Sets up an Express app with MySQL-backed sessions using connect-mysql-store. Demonstrates store initialization with connection URL and session usage.

const express = require('express'); const session = require('express-session'); const MySQLStore = require('connect-mysql-store'); const app = express(); app.use(session({ secret: 'your-secret-key', resave: true, saveUninitialized: false, store: new MySQLStore({ url: 'mysql://user:password@localhost/database', table: 'sessions' }) })); app.get('/', (req, res) => { if (!req.session.views) req.session.views = 0; req.session.views++; res.send(`Views: ${req.session.views}`); }); app.listen(3000);
Debug
Known issues
gotchaRequires a predefined MySQL table with specific columns (sid, session, updated). The table must be created manually before use.
fix
Run the CREATE TABLE SQL provided in the README to create the sessions table.
affects: >=0.1.0
breakingThe `url` option is required; if omitted, the store will throw an error on instantiation.
fix
Provide a valid MySQL connection string via the `url` option.
affects: >=0.1.0
deprecatedThis package is no longer actively maintained. Consider using more up-to-date alternatives like 'express-mysql-session'.
fix
Migrate to a maintained package like 'express-mysql-session'.
affects: >=0.2.0
gotchaThe `session` column length is limited to 2048 characters; large sessions may be truncated silently.
fix
Alter the table to increase VARCHAR length or use TEXT type for session column.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Can't set session store after session middleware is used
The store must be passed to session() synchronously; re-assigning req.session.store after middleware start is not allowed.
fix
Ensure the store is initialized and passed in the session options object before applying app.use(session(...)).
MySQLStore is not a constructor
CommonJS require incorrectly used as named import or ESM import not transpiled.
fix
Use correct CommonJS require: const MySQLStore = require('connect-mysql-store');
ER_ACCESS_DENIED_ERROR: Access denied for user ...
Invalid MySQL credentials in the connection url.
fix
Check the url option format: mysql://username:password@host/database
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
express-sessionrequiredRequired peer dependency; this store implements express-session's Store interface.
mysql2requiredUsed for MySQL database connectivity. The package uses mysql2 internally for promise-based queries.
Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
connect-mysql-store — npm install connect-mysql-store · libregistry