Registry / database / pino-mysql

pino-mysql

JSON →
library1.3.0jsnpmunverified

A Pino transport for MySQL and MariaDB databases. Current stable version is 1.3.0. This package allows piping Pino log output into a MySQL or MariaDB table. It supports mapping log fields to database columns, including JSON column type. The transport is designed to work as a standalone CLI utility consuming pino's NDJSON via stdin. It is useful for centralized logging in Node.js applications. Updates are infrequent; no major breaking changes since v1.0.0.

npm install pino-mysql
INSTALL
IMPORT
SIG · PINO-MYSQL
P
pino-mysql
databasejavascriptv1.3.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.

pino-mysql (CLI)
node myapp | npx pino-mysql -c db-config.json
pino-mysql -c db-config.json < myapp.log
Designed to be piped from application stdout; using input redirection may not work correctly.
Configuration file
Create a JSON config file with host, user, password, database, table, and columns.
Using environment variables only without config file
The package requires a configuration file; environment variables are not supported for all settings.
Table column mapping
Use "columns": { "log": "*" } to store entire log as JSON.
Omitting columns field entirely
You must specify at least one column mapping, otherwise no data is written.

Demonstrates installing pino-mysql, creating a log table, configuring column mappings, and piping pino output into the transport.

npm install pino-mysql # Create database table mysql -u root -e "CREATE DATABASE IF NOT EXISTS logs_db; USE logs_db; CREATE TABLE logs (log JSON, unix BIGINT UNSIGNED, name VARCHAR(64), url VARCHAR(64));" # Create config file db-config.json cat <<EOF > db-config.json { "host": "localhost", "user": "root", "password": "", "database": "logs_db", "table": "logs", "columns": { "log": "*", "unix": "time", "name": "name", "url": "req.url" } } EOF # Use with a pino app (e.g., node -e "const pino = require('pino'); pino().info({name:'test',req:{url:'/home'}},'hello')") node myapp | npx pino-mysql -c db-config.json
Debug
Known issues
gotchaThe package expects logs in NDJSON format via stdin; other formats will cause errors.
fix
Ensure you pipe only pino log output (or any NDJSON) into the transport.
affects: >=1.0.0
gotchaThe configuration file must contain all required fields (host, user, password, database, table, columns). Missing fields cause silent failures.
fix
Verify the config JSON includes 'host', 'user', 'password', 'database', 'table', and 'columns'.
affects: >=1.0.0
gotchaColumn mappings using dot notation (e.g., 'req.url') rely on the delimiter setting. Default delimiter is '.'; if your log fields contain dots, you must set a custom delimiter.
fix
Set 'delimiter' in config if your log keys contain periods.
affects: >=1.0.0
gotchaThe 'log' column mapped with '*' will store the entire JSON object. Make sure the column type is JSON or TEXT to avoid truncation.
fix
Use MySQL JSON column type or a large TEXT column.
affects: >=1.0.0
deprecatedThe package does not support TypeScript types natively; no @types/pino-mysql exists.
fix
Use a type assertion or declare module manually if using TypeScript.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pino-mysql'
pino-mysql is not installed or not found when using npx without installation.
fix
Run 'npm install -g pino-mysql' or use 'npx pino-mysql' (note: npx may need network access to download).
Client does not support authentication protocol requested by server; consider upgrading MySQL client
MySQL 8.0 uses caching_sha2_password by default, which older mysql2 versions may not support.
fix
Update mysql2 driver: 'npm install mysql2@latest' or alter MySQL user to use mysql_native_password: 'ALTER USER 'user'@'host' IDENTIFIED WITH mysql_native_password BY 'password';'
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 '?' at line 1
Incorrect SQL syntax when inserting logs, often due to missing columns mapping or mismatched table schema.
fix
Verify that the table columns match the config columns exactly (including names and data types).
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
pinorequiredpino-mysql is a transport for pino and expects pino log format
mysql2requiredMySQL driver used for database connections
Agent activity
2 hits · last 30 days
node
2
Resources
pino-mysql — npm install pino-mysql · libregistry