Registry / database / mysql-import-fu3e

mysql-import-fu3e

JSON →
library5.1.2jsnpmunverified

A Node.js library for importing .sql dump files into a MySQL database. Current stable version is 5.1.2. It supports importing single or multiple SQL files, directories, and arrays of paths with progress and completion callbacks. This is a fork of Pamblam/mysql-import with updated dependencies and Node.js engine requirements >5.0.0. Alternative to command-line mysql client, offering programmatic control and event-driven import monitoring.

npm install mysql-import-fu3e
INSTALL
IMPORT
SIG · MYSQL-IMPORT-FU3E
M
mysql-import-fu3e
databasejavascriptv5.1.2
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.

Importer
const Importer = require('mysql-import-fu3e');
import Importer from 'mysql-import-fu3e';
This package uses CommonJS and does not support ES modules. Use require().
Importer
const { Importer } = require('mysql-import-fu3e');
import { Importer } from 'mysql-import-fu3e';
The package exports a single constructor via module.exports, so destructuring require works but direct named import does not.
importer
const importer = new Importer({host, user, password, database});
const importer = new Importer(host, user, password, database);
Constructor expects an options object, not positional arguments.

Imports a SQL dump file with progress tracking using the Importer class.

const Importer = require('mysql-import-fu3e'); const importer = new Importer({ host: process.env.MYSQL_HOST ?? 'localhost', user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', database: process.env.MYSQL_DATABASE ?? 'mydb' }); importer.onProgress(progress => { const percent = Math.floor(progress.bytes_processed / progress.total_bytes * 10000) / 100; console.log(`${percent}% Completed`); }); importer.import('path/to/dump.sql') .then(() => { const files_imported = importer.getImported(); console.log(`${files_imported.length} SQL file(s) imported.`); }) .catch(err => console.error(err));
Debug
Known issues
gotchaConstructor expects an options object, not individual arguments. Passing host, user as separate strings will cause a connection error.
fix
Use new Importer({host: 'localhost', user: 'root', ...})
affects: >=5.0.0
gotchaThe package uses CommonJS. Attempting to use ES module import syntax will fail.
fix
Use require() instead of import.
affects: >=5.0.0
deprecatedThe 'mysql' package is deprecated; consider using 'mysql2' for better performance and security.
fix
Switch to a library that uses mysql2, or manually replace dependency.
affects: >=5.0.0
gotchaEncoding must be set before import. Setting after import starts has no effect.
fix
Call importer.setEncoding('utf8') before importer.import().
affects: >=5.0.0
gotchaThe import() method resolves when all files are processed. Errors during import are caught by the promise rejection, but callbacks may fire after rejection.
fix
Handle both promise rejection and onDumpCompleted callback errors.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: Importer is not a constructor
Using ES module import syntax with a CommonJS-only package.
fix
Change to const Importer = require('mysql-import-fu3e');
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Incorrect or missing password, or the user does not have access from the specified host.
fix
Verify credentials and host in the options object passed to the Importer constructor.
Error: Cannot read property 'length' of undefined
import() called with an empty argument list or invalid path that doesn't resolve to any files.
fix
Provide at least one valid file or directory path to import().
Upgrade
Version history
5.1.2latest on npm
Audit
Dependencies
mysqloptionalRequired for MySQL database connection and query execution.
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-import-fu3e — npm install mysql-import-fu3e · libregistry