Registry / database / winston-mysql

winston-mysql

JSON →
library1.1.1jsnpmunverified

MySQL transport plugin for winston@3.x logger, version 1.1.1. Enables logging directly to a MySQL database table with customizable fields and optional JSON meta support (requires MySQL 5.7+). Designed specifically for winston 3.x, it supports default and custom table schemas. Release cadence is low; no updates since 2020. Differentiator: simple integration with winston for MySQL logging, alternative to other transports like winston-database.

npm install winston-mysql
INSTALL
IMPORT
SIG · WINSTON-MYSQL
W
winston-mysql
databasejavascriptv1.1.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.

winstonMysql
import winstonMysql from 'winston-mysql'
const winstonMysql = require('winston-mysql')
Default ES module import; package does not export named transports.
WinstonMysql
import WinstonMysql from 'winston-mysql'
import { WinstonMysql } from 'winston-mysql'
Default export is a class; named import will fail.
(transport)
const { transports } = require('winston'); const winstonMysql = require('winston-mysql'); logger.add(new winstonMysql(options));
const winstonMysql = require('winston-mysql').WinstonMysql;
CommonJS usage: package exports default, not named.

Shows how to create a winston logger with MySQL transport using environment variables for credentials.

import winston from 'winston'; import winstonMysql from 'winston-mysql'; const options = { host: process.env.MYSQL_HOST ?? 'localhost', user: process.env.MYSQL_USER ?? 'logger', password: process.env.MYSQL_PASSWORD ?? '', database: process.env.MYSQL_DATABASE ?? 'WinstonTest', table: 'sys_logs_default' }; const logger = winston.createLogger({ level: 'debug', format: winston.format.json(), transports: [ new winstonMysql(options) ] }); logger.info('Hello from winston-mysql');
Debug
Known issues
gotchaSchema mismatch: table columns must exactly match default (level, message, meta, timestamp) or custom fields mapping.
fix
Create table with correct columns or use 'fields' option to map to existing columns.
affects: all
gotchaJSON meta field only works with MySQL 5.7+; older versions require VARCHAR meta.
fix
Use MySQL 5.7+ for JSON column type or use string meta column.
affects: all
deprecatedPackage uses mysql driver (unmaintained) instead of mysql2. May cause compatibility issues with newer MySQL versions.
fix
Consider forking or patching to use mysql2 driver.
affects: >=1.1.1
gotchaNo connection pooling; each log may create a new connection causing performance overhead.
fix
Implement connection pooling via external module or modify transport.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'winston-mysql'
Package not installed.
fix
Run 'npm install winston-mysql'.
Error: ER_BAD_FIELD_ERROR: Unknown column 'level' in 'field list'
Table schema does not match default fields or custom fields mapping is missing.
fix
Ensure table has columns: level, message, meta, timestamp (or use fields option).
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JSON'
Using JSON meta column on MySQL <5.7.
fix
Upgrade MySQL to 5.7+ or change meta column to VARCHAR.
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running or connection refused.
fix
Start MySQL server and check host/port in options.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
winstonrequiredPeer dependency; transport plugin for winston 3.x.
mysqlrequiredDatabase driver; used internally to connect and query MySQL.
Agent activity
24 hits · last 30 days
node
20
Meta
2
OpenAI (training)
1
Resources
winston-mysql — npm install winston-mysql · libregistry