Import MySQL files with Node!
via NPM:
$ npm install --save-dev mysql-import
Via Github:
git clone https://github.com/Pamblam/mysql-import.git
const host = 'localhost';
const user = 'root';
const password = 'password';
const database = 'mydb';
const Importer = require('mysql-import');
const importer = new Importer({host, user, password, database});
importer.import('path/to/dump.sql').then(()=>{
var files_imported = importer.getImported();
console.log(`${files_imported.length} SQL file(s) imported.`);
}).catch(err=>{
console.error(err);
});
The constructor requires an object with a host
, user
, and password
parameter. Passing in a database parameter is optional.
Get an array of files imported.
Set the encoding to use when reading import files. Supported arguments are: utf8
, ucs2
, utf16le
, latin1
, ascii
, base64
, or hex
.
Set or change the database to import to.
Import an .sql
file or files into the database. This method will take...
- Any number of paths to individual
.sql
files.importer.import('path/to/dump1.sql', 'path/to/dum2.sql')
- Any number of paths that contain any number of
.sql
files.importer.import('path/to/mysqldumps/')
- Any number of arrays containing either of the above.
importer.import(['path/to/dump.sql', 'path/to/dumps/'])
- Any combination of any of the above.
Disconnects the connection. If graceful
is switched to false it will force close any connections. This is called automatically after files are imported so typically this method should never be required.
Contributions are more than welcome! Please check out the Contributing Guidelines for this project.