Mysql Dump
Create a backup of a MySQL database.
Installation
$ npm install mysqldump
If you're using this package in typescript, you should also
$ npm install @types/node
Usage
import mysqldump from 'mysqldump';
mysqldump({
connection: {
host: 'localhost',
user: 'root',
password: '123456',
database: 'my_database',
},
dumpToFile: './dump.sql',
});
mysqldump({
connection: {
host: 'localhost',
user: 'root',
password: '123456',
database: 'my_database',
},
dumpToFile: './dump.sql.gz',
compressFile: true,
});
const result = await mysqldump({
connection: {
host: 'localhost',
user: 'root',
password: '123456',
database: 'my_database',
},
});
Result
The returned result contains the dump property, which is split into schema and data.
export default interface DumpReturn {
dump : {
schema : string | null
data : string | null
trigger : string | null
}
tables : Table[]
}
Options
All the below options are documented in the typescript declaration file:
export interface ConnectionOptions {
host?: string;
port?: number;
database: string;
user: string;
password: string;
charset?: string;
ssl?: 'Amazon RDS' | null | {
ca?: string | Buffer;
cert?: string | Buffer;
ciphers?: string;
crl?: string | Array<string>;
honorCipherOrder?: boolean;
key?: string | Buffer;
passphrase?: string;
pfx?: string | Buffer;
rejectUnauthorized?: boolean;
};
}
export interface SchemaDumpOptions {
autoIncrement?: boolean;
engine?: boolean;
format?: boolean;
table?: {
ifNotExist?: boolean;
dropIfExist?: boolean;
charset?: boolean | string;
};
view?: {
createOrReplace?: boolean;
definer?: boolean;
algorithm?: boolean;
sqlSecurity?: boolean;
};
}
export interface TriggerDumpOptions {
delimiter?: string | false;
dropIfExist?: boolean;
definer?: boolean;
}
export interface DataDumpOptions {
format?: boolean;
verbose?: boolean;
lockTables?: boolean;
includeViewData?: boolean;
maxRowsPerInsertStatement?: number;
returnFromFunction?: boolean;
where?: {
[k: string]: string;
};
}
export interface DumpOptions {
tables?: Array<string>;
excludeTables?: boolean;
schema?: false | SchemaDumpOptions;
data?: false | DataDumpOptions;
trigger?: false | TriggerDumpOptions;
}
export interface Options {
connection: ConnectionOptions;
dump?: DumpOptions;
dumpToFile?: string | null;
compressFile?: boolean;
}
export interface ColumnList {
[k: string]: {
type: string;
nullable: boolean;
};
}
export interface Table {
name: string;
schema: string | null;
data: string | null;
columns: ColumnList;
columnsOrdered: Array<string>;
isView: boolean;
triggers: Array<string>;
}
export interface DumpReturn {
dump: {
schema: string | null;
data: string | null;
trigger: string | null;
};
tables: Array<Table>;
}
export default function main(inputOptions: Options): Promise<DumpReturn>;
export as namespace mysqldump;
The MIT License
Contributing
Local Installation
Make sure to first install all the required development dependencies:
yarn
// or
npm install .
Linting
We use eslint in conjunction with typescript-eslint-parser for code linting.
PRs are required to pass the linting with no errors and preferrably no warnings.
Testing
Tests can be run via the test
script - yarn test
/ npm test
.
Additionally it's required that you do a build and run your test against the public package to ensure the build doesn't cause regressions - yarn run test-prod
/ npm run test-prod
.
PRs are required to maintain the 100% test coverage, and all tests must pass successfully.