https://github.com/sirwanafifi/sqldumpjs
A tiny wrapper around mysqldump utility to generate a dump file of a MySQL database.
https://github.com/sirwanafifi/sqldumpjs
database mysql mysqldump
Last synced: 4 months ago
JSON representation
A tiny wrapper around mysqldump utility to generate a dump file of a MySQL database.
- Host: GitHub
- URL: https://github.com/sirwanafifi/sqldumpjs
- Owner: SirwanAfifi
- License: mit
- Created: 2020-04-24T14:13:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-16T07:35:43.000Z (over 5 years ago)
- Last Synced: 2025-07-12T08:40:52.385Z (12 months ago)
- Topics: database, mysql, mysqldump
- Language: TypeScript
- Homepage:
- Size: 16.6 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MySQLDump.js
A tiny wrapper around `mysqldump` utility to generate a dump file of a MySQL database.
### Usage
- `yarn add mysqldumpjs`
- Import the package:
```ts
import MySQLDump from "mysqldumpjs";
```
### Dump all tables
```js
new MySQLDump({
dbName: process.env.DATABASE_NAME,
password: process.env.DATABASE_PASSWORD,
}).doBackup("outputFileName");
```
### Dump specific tables
```js
new MySQLDump({
dbName: process.env.DATABASE_NAME,
password: process.env.DATABASE_PASSWORD,
flags: {
tables: ["customers", "orders"],
compact: true,
},
}).doBackup("outputFileName");
```
### Dump tables with where clause
```js
new MySQLDump({
dbName: process.env.DATABASE_NAME,
password: process.env.DATABASE_PASSWORD,
flags: {
tables: [
"customers",
"orders",
{ table: "products", where: "product_id = 4" },
{ table: "shippers", where: "name = 'Hettinger LLC'" },
],
compact: true,
},
}).doBackup("outputFileName");
```
### Options
These are `mysqldump` options you can pass in to a `MySQLDump` instance.
| Option | Description | Default |
| ----------------- | :-------------------------------------------------------------------: | ------: |
| `tables` | The list of tables you want to export | `[]` |
| `noData` | Do not dump table contents | `false` |
| `where` | Dump only rows selected by given WHERE condition | `false` |
| `compact` | Produce more compact output | `false` |
| `addDropDatabase` | Add DROP DATABASE statement before each CREATE DATABASE statement | `false` |
| `addDropTable` | Add DROP TABLE statement before each CREATE TABLE statement | `false` |
| `withRoutines` | Dump stored routines (procedures and functions) from dumped databases | `false` |