Registry / database / node-mysql-backup

node-mysql-backup

JSON →
library1.0.1jsnpmunverified

Node.js module for backing up MySQL database tables to SQL dump files. Version 1.0.1 is the latest stable. It provides simple API to export specified tables with options like extended inserts, DROP TABLE statements, locks, and key disabling. The package is a fork from a GitHub issue that optimizes performance over older alternatives. It depends on 'mysql' and 'extend' packages. Easy to use with callback-based API.

npm install node-mysql-backup
INSTALL
IMPORT
SIG · NODE-MYSQL-BACKUP
N
node-mysql-backup
databasejavascriptv1.0.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.

default
✓ const mysqldump = require('node-mysql-backup');
✗ import mysqldump from 'node-mysql-backup';
CommonJS module; no ESM export. Use require.
the function itself is named 'mysqldump' in code
✓ const mysqldump = require('node-mysql-backup'); mysqldump(options, callback);
✗ const { mysqldump } = require('node-mysql-backup');
Default export is the function; named import not supported.
options object
✓ const mysqldump = require('node-mysql-backup'); mysqldump({ host: 'localhost', user: 'root', password: 'pass', database: 'mydb', dest: './dump.sql' }, function(err) { ... });
✗ const mysqldump = require('node-mysql-backup'); mysqldump({ host: 'localhost', user: 'root', password: 'pass', database: 'mydb' }, callback); // missing dest - will crash
dest option is mandatory

Exports specific MySQL tables to a SQL dump file using options like extended inserts and DROP TABLE.

const mysqldump = require('node-mysql-backup'); mysqldump({ host: 'localhost', user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'testdb', tables: ['users', 'orders'], extendedInsert: true, addDropTable: true, addLocks: true, disableKeys: true, dest: './backup.sql' }, function (err) { if (err) { console.error('Backup failed:', err); process.exit(1); } console.log('Backup completed successfully'); });
Debug
Known issues
breakingCallback is mandatory; if omitted, function will throw 'callback is not a function'
fix
Always provide a callback function as second argument.
affects: >=1.0.0
gotchadest option is required; if missing, script will try to write to undefined path causing error
fix
Always specify dest option with a writable file path.
affects: >=1.0.0
deprecatedPackage relies on mysql npm package which is not maintained; recommend using mysql2 instead (but this package requires mysql)
fix
Consider using mysqldump package or mysql2-based alternatives.
affects: >=1.0.0
gotchaPassword sent over network without encryption; ensure MySQL server uses TLS
fix
Use ssl option or connect over SSH tunnel.
affects: >=1.0.0
breakingIf function called multiple times without completion of previous, it may corrupt output file due to shared write stream
fix
Ensure sequential calls or use a mutex. Not recommended for concurrent backups.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: callback is not a function
Missing second argument callback when calling mysqldump()
fix
mysqldump(options, function(err) { ... });
Error: Cannot read property 'host' of undefined
First argument options is undefined/null
fix
mysqldump({ host: ..., ... }, callback);
Error: ENOENT: no such file or directory, open 'undefined'
dest option not provided or undefined
fix
Include 'dest' property in options object with a valid file path.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
mysqlrequiredCore MySQL client for database connection
extendrequiredDeep merge of default options with user options
Agent activity
7 hits · last 30 days
node
6
Resources
node-mysql-backup — npm install node-mysql-backup · libregistry