{"library":"mysql-import","title":"Node.js MySQL SQL File Importer","description":"mysql-import is a Node.js library designed to facilitate the programmatic import of `.sql` dump files into a MySQL database. Currently at version 5.0.26, the package provides a streamlined API for tasks such as database seeding, migration, or restoring backups. It differs from general ORMs or query builders by focusing solely on bulk SQL import operations. A key differentiator is its event-driven progress tracking (`onProgress`, `onDumpCompleted`), allowing developers to monitor long-running imports in real-time, which is crucial for large datasets. The library leverages Node.js streams and underlying MySQL client binaries to efficiently process SQL files of various sizes, making it a robust solution for environments requiring automated database provisioning or data synchronization.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install mysql-import"],"cli":null},"imports":["const Importer = require('mysql-import');","import Importer from 'mysql-import';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const host = 'localhost';\nconst user = 'root';\nconst password = 'password';\nconst database = 'mydb';\n\nconst Importer = require('mysql-import');\nconst importer = new Importer({host, user, password, database});\n\nimporter.onProgress(progress=>{\n  var percent = Math.floor(progress.bytes_processed / progress.total_bytes * 10000) / 100;\n  console.log(`${percent}% Completed`);\n});\n\nimporter.import('path/to/dump.sql').then(()=>{\n  var files_imported = importer.getImported();\n  console.log(`${files_imported.length} SQL file(s) imported.`);\n}).catch(err=>{\n  console.error(err);\n});","lang":"javascript","description":"Demonstrates how to initialize the Importer, set up progress tracking, and import a single SQL file.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}