Registry / database / mysql-baileys

mysql-baileys

JSON →
library1.5.4jsnpmunverified

Implementation of MySQL authentication state storage for Baileys, a WhatsApp Web library. This package provides a MySQL-based authentication state handler that allows persisting Baileys authentication data (creds, keys, sessions) in a MySQL database. It is currently at version 1.5.4 and is maintained by bobslavtriev. Key differentiators include full TypeScript support with type definitions, seamless integration with mysql2 library, and support for managing multiple sessions via table prefix option. It is a lightweight connector that implements Baileys' AuthenticationState interface, making it easy to use MySQL as backend for WhatsApp bot sessions.

npm install mysql-baileys
INSTALL
IMPORT
SIG · MYSQL-BAILEYS
M
mysql-baileys
databasejavascriptv1.5.4
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.

useMySQLAuthState
import { useMySQLAuthState } from 'mysql-baileys'
const { useMySQLAuthState } = require('mysql-baileys')
Package is ESM-only; 'require' will fail in Node.js ≥12 with ESM enabled.
MySQLAuthOptions
import { MySQLAuthOptions } from 'mysql-baileys'
import type { MySQLAuthOptions } from 'mysql-baileys'
This is a named interface export; you can use 'import type' if only using for type annotations, but the correct export is through 'import { MySQLAuthOptions }'.
default
import mysqlAuth from 'mysql-baileys'
import { default as mysqlAuth } from 'mysql-baileys'
Package also exports a default object containing all exports. However, using named imports is preferred for tree-shaking.

Shows how to create a MySQL connection pool and initialize the authentication state for Baileys using mysql-baileys.

import { useMySQLAuthState } from 'mysql-baileys'; import { createPool } from 'mysql2/promise'; const pool = createPool({ host: 'localhost', user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'whatsapp_bot', waitForConnections: true, connectionLimit: 10, }); async function startBot() { const { state, saveCreds } = await useMySQLAuthState({ pool, tablePrefix: 'wa_', }); // Use state and saveCreds with Baileys console.log('MySQL auth state initialized'); } startBot().catch(console.error);
Debug
Known issues
gotchaThe package requires mysql2 (not mysql) as a peer dependency. Using 'mysql' package will cause runtime errors.
fix
Install mysql2: npm install mysql2
affects: >=1.0.0
gotchaThe option 'tablePrefix' must be a non-empty string if provided; otherwise, it defaults to 'wa_'. Ensure your MySQL user has CREATE TABLE privileges.
fix
Set tablePrefix to a valid string or omit it to use default.
affects: >=1.0.0
gotchaWhen using multiple sessions with different prefixes, ensure each session uses a unique tablePrefix to avoid data collision.
fix
Pass distinct tablePrefix values for each session.
affects: >=1.0.0
gotchaThe database tables are created automatically if they don't exist. The package does not support migration; manual schema changes may break the state store.
fix
Do not manually alter the tables created by the package.
affects: >=1.0.0
deprecatedSome users have reported deprecation warnings for using 'authentication' property in Baileys v6. Check Baileys changelog for migration to 'auth'.
fix
Update to latest Baileys v6 and use 'auth' instead of 'authentication'.
affects: ~1.0
Errors
Common errors & fixes
Error: Cannot find module 'mysql-baileys'
Package not installed or incorrect import path.
fix
Run 'npm install mysql-baileys' and ensure your project uses ESM (type: 'module' in package.json or .mjs extension).
TypeError: pool.query is not a function
Using 'mysql' package instead of 'mysql2'.
fix
Replace 'mysql' with 'mysql2/promise' and ensure the pool is created with createPool.
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server
MySQL server uses caching_sha2_password and the client driver needs to enable it.
fix
Alter MySQL user: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; or update mysql2 connection options.
TypeError: Cannot destructure property 'state' of (intermediate value) as it is undefined.
useMySQLAuthState is not properly imported or called.
fix
Ensure you import { useMySQLAuthState } from 'mysql-baileys' and call it correctly with the pool argument.
Upgrade
Version history
1.5.4latest on npm
Audit
Dependencies
mysql2requiredRequired as peer dependency for database connectivity.
@whiskeysockets/baileysrequiredPackage implements authentication state for Baileys; needed for type definitions and integration.
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-baileys — npm install mysql-baileys · libregistry