{"id":13574663,"url":"https://github.com/bradzacher/mysqldump","last_synced_at":"2025-04-04T15:31:42.478Z","repository":{"id":48692722,"uuid":"42830758","full_name":"bradzacher/mysqldump","owner":"bradzacher","description":"Node Module to Create a Backup from MySQL","archived":true,"fork":false,"pushed_at":"2021-07-14T00:20:39.000Z","size":750,"stargazers_count":167,"open_issues_count":1,"forks_count":86,"subscribers_count":12,"default_branch":"develop","last_synced_at":"2024-05-21T02:02:13.776Z","etag":null,"topics":["backup","database","mysql"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bradzacher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"bradzacher"}},"created_at":"2015-09-20T21:41:18.000Z","updated_at":"2024-03-21T23:01:20.000Z","dependencies_parsed_at":"2022-09-08T08:11:40.845Z","dependency_job_id":null,"html_url":"https://github.com/bradzacher/mysqldump","commit_stats":null,"previous_names":["assignar/mysqldump"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradzacher%2Fmysqldump","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradzacher%2Fmysqldump/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradzacher%2Fmysqldump/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradzacher%2Fmysqldump/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bradzacher","download_url":"https://codeload.github.com/bradzacher/mysqldump/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247202872,"owners_count":20900858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backup","database","mysql"],"created_at":"2024-08-01T15:00:53.500Z","updated_at":"2025-04-04T15:31:37.466Z","avatar_url":"https://github.com/bradzacher.png","language":"TypeScript","funding_links":["https://github.com/sponsors/bradzacher"],"categories":["TypeScript"],"sub_categories":[],"readme":"# Mysql Dump\n\n[![npm version](https://badge.fury.io/js/mysqldump.svg)](https://npmjs.com/package/mysqldump) [![Build Status](https://travis-ci.org/bradzacher/mysqldump.svg)](https://travis-ci.org/bradzacher/mysqldump)\n\n[This codebase is no longer actively maintained. The package will continue working, but support and changes are no longer provided.](https://github.com/bradzacher/mysqldump/issues/134)\n\nCreate a backup of a MySQL database.\n\n## Installation\n\n```bash\n$ npm install mysqldump\n```\n\nIf you're using this package in typescript, you should also\n\n```bash\n$ npm install @types/node\n```\n\n## Usage\n\n```typescript\nimport mysqldump from 'mysqldump';\n// or const mysqldump = require('mysqldump')\n\n// dump the result straight to a file\nmysqldump({\n    connection: {\n        host: 'localhost',\n        user: 'root',\n        password: '123456',\n        database: 'my_database',\n    },\n    dumpToFile: './dump.sql',\n});\n\n// dump the result straight to a compressed file\nmysqldump({\n    connection: {\n        host: 'localhost',\n        user: 'root',\n        password: '123456',\n        database: 'my_database',\n    },\n    dumpToFile: './dump.sql.gz',\n    compressFile: true,\n});\n\n// return the dump from the function and not to a file\nconst result = await mysqldump({\n    connection: {\n        host: 'localhost',\n        user: 'root',\n        password: '123456',\n        database: 'my_database',\n    },\n});\n```\n\n## Result\n\nThe returned result contains the dump property, which is split into schema and data.\n\n```TS\nexport default interface DumpReturn {\n    /**\n     * The result of the dump\n     */\n    dump : {\n        /**\n         * The concatenated SQL schema dump for the entire database.\n         * Null if configured not to dump.\n         */\n        schema : string | null\n        /**\n         * The concatenated SQL data dump for the entire database.\n         * Null if configured not to dump.\n         */\n        data : string | null\n        /**\n         * The concatenated SQL trigger dump for the entire database.\n         * Null if configured not to dump.\n         */\n        trigger : string | null\n    }\n    tables : Table[]\n}\n\n```\n\n## Options\n\nAll the below options are documented in the [typescript declaration file](./dist/mysqldump.d.ts):\n\n```TS\nexport interface ConnectionOptions {\n    /**\n     * The database host to connect to.\n     * Defaults to 'localhost'.\n     */\n    host?: string;\n    /**\n     * The port on the host to connect to.\n     * Defaults to 3306.\n     */\n    port?: number;\n    /**\n     * The database to dump.\n     */\n    database: string;\n    /**\n     * The DB username to use to connect.\n     */\n    user: string;\n    /**\n     * The password to use to connect.\n     */\n    password: string;\n    /**\n     * The charset to use for the connection.\n     * Defaults to 'UTF8_GENERAL_CI'.\n     */\n    charset?: string;\n    /**\n     * SSL configuration options.\n     * Passing 'Amazon RDS' will use Amazon's RDS CA certificate.\n     *\n     * Otherwise you can pass the options which get passed to tls.createSecureContext.\n     * See: https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options\n     */\n    ssl?: 'Amazon RDS' | null | {\n        /**\n         * Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla.\n         */\n        ca?: string | Buffer;\n        /**\n         * Optional cert chains in PEM format.\n         */\n        cert?: string | Buffer;\n        /**\n         * Optional cipher suite specification, replacing the default.\n         */\n        ciphers?: string;\n        /**\n         * Optional PEM formatted CRLs (Certificate Revocation Lists).\n         */\n        crl?: string | Array\u003cstring\u003e;\n        /**\n         * Attempt to use the server's cipher suite preferences instead of the client's.\n         */\n        honorCipherOrder?: boolean;\n        /**\n         * Optional private keys in PEM format.\n         */\n        key?: string | Buffer;\n        /**\n         * Optional shared passphrase used for a single private key and/or a PFX.\n         */\n        passphrase?: string;\n        /**\n         * Optional PFX or PKCS12 encoded private key and certificate chain.\n         */\n        pfx?: string | Buffer;\n        /**\n         * DO NOT USE THIS OPTION UNLESS YOU REALLY KNOW WHAT YOU ARE DOING!!!\n         * Set to false to allow connection to a MySQL server without properly providing the appropraite CA to trust.\n         */\n        rejectUnauthorized?: boolean;\n    };\n}\nexport interface SchemaDumpOptions {\n    /**\n     * True to include autoincrement values in schema, false otherwise.\n     * Defaults to true.\n     */\n    autoIncrement?: boolean;\n    /**\n     * True to include engine values in schema, false otherwise.\n     * Defaults to true.\n     */\n    engine?: boolean;\n    /**\n     * True to run a sql formatter over the output, false otherwise.\n     * Defaults to true.\n     */\n    format?: boolean;\n    /**\n     * Options for table dumps\n     */\n    table?: {\n        /**\n         * Guard create table calls with an \"IF NOT EXIST\"\n         * Defaults to true.\n         */\n        ifNotExist?: boolean;\n        /**\n         * Drop tables before creation (overrides `ifNotExist`).\n         * Defaults to false.\n         */\n        dropIfExist?: boolean;\n        /**\n         * Include the `DEFAULT CHARSET = x` at the end of the table definition\n         * Set to true to include the value form the DB.\n         * Set to false to exclude it altogether.\n         * Set to a string to explicitly set the charset.\n         * Defaults to true.\n         */\n        charset?: boolean | string;\n    };\n    view?: {\n        /**\n         * Uses `CREATE OR REPLACE` to define views.\n         * Defaults to true.\n         */\n        createOrReplace?: boolean;\n        /**\n         * Include the `DEFINER = {\\`user\\`@\\`host\\` | CURRENT_USER}` in the view definition or not\n         * Defaults to false.\n         */\n        definer?: boolean;\n        /**\n         * Include the `ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}` in the view definition or not\n         * Defaults to false.\n         */\n        algorithm?: boolean;\n        /**\n         * Incldue the `SQL SECURITY {DEFINER | INVOKER}` in the view definition or not\n         * Defaults to false.\n         */\n        sqlSecurity?: boolean;\n    };\n}\nexport interface TriggerDumpOptions {\n    /**\n     * The temporary delimiter to use between statements.\n     * Set to false to not use delmiters\n     * Defaults to ';;'.\n     */\n    delimiter?: string | false;\n    /**\n     * Drop triggers before creation.\n     * Defaults to false.\n     */\n    dropIfExist?: boolean;\n    /**\n     * Include the `DEFINER = {\\`user\\`@\\`host\\` | CURRENT_USER}` in the view definition or not\n     * Defaults to false.\n     */\n    definer?: boolean;\n}\nexport interface DataDumpOptions {\n    /**\n     * True to run a sql formatter over the output, false otherwise.\n     * Defaults to true.\n     */\n    format?: boolean;\n    /**\n     * Include file headers in output\n     * Defaults to true.\n     */\n    verbose?: boolean;\n    /**\n     * Use a read lock during the data dump (see: https://dev.mysql.com/doc/refman/5.7/en/replication-solutions-backups-read-only.html)\n     * Defaults to false.\n     */\n    lockTables?: boolean;\n    /**\n     * Dump data from views.\n     * Defaults to false.\n     */\n    includeViewData?: boolean;\n    /**\n     * Maximum number of rows to include in each multi-line insert statement\n     * Defaults to 1 (i.e. new statement per row).\n     */\n    maxRowsPerInsertStatement?: number;\n    /**\n     * True to return the data in a function, false to not.\n     * This is useful in databases with a lot of data.\n     *\n     * We stream data from the DB to reduce the memory footprint.\n     * However note that if you want the result returned from the function,\n     * this will result in a larger memory footprint as the string has to be stored in memory.\n     *\n     * Defaults to false if dumpToFile is truthy, or true if not dumpToFile is falsey.\n     */\n    returnFromFunction?: boolean;\n    /**\n     * A map of tables to additional where strings to add.\n     * Use this to limit the number of data that is dumped.\n     * Defaults to no limits\n     */\n    where?: {\n        [k: string]: string;\n    };\n}\nexport interface DumpOptions {\n    /**\n     * The list of tables that you want to dump.\n     * Defaults to all tables (signalled by passing an empty array).\n     */\n    tables?: Array\u003cstring\u003e;\n    /**\n     * True to use the `tables` options as a blacklist, false to use it as a whitelist.\n     * Defaults to false.\n     */\n    excludeTables?: boolean;\n    /**\n     * Explicitly set to false to not include the schema in the dump.\n     * Defaults to including the schema.\n     */\n    schema?: false | SchemaDumpOptions;\n    /**\n     * Explicitly set to false to not include data in the dump.\n     * Defaults to including the data.\n     */\n    data?: false | DataDumpOptions;\n    /**\n     * Explicitly set to false to not include triggers in the dump.\n     * Defaults to including the triggers.\n     */\n    trigger?: false | TriggerDumpOptions;\n}\nexport interface Options {\n    /**\n     * Database connection options\n     */\n    connection: ConnectionOptions;\n    /**\n     * Dump configuration options\n     */\n    dump?: DumpOptions;\n    /**\n     * Set to a path to dump to a file.\n     * Exclude to just return the string.\n     */\n    dumpToFile?: string | null;\n    /**\n     * Should the output file be compressed (gzip)?\n     * Defaults to false.\n     */\n    compressFile?: boolean;\n}\nexport interface ColumnList {\n    /**\n     * Key is the name of the column\n     */\n    [k: string]: {\n        /**\n         * The type of the column as reported by the underlying DB.\n         */\n        type: string;\n        /**\n         * True if the column is nullable, false otherwise.\n         */\n        nullable: boolean;\n    };\n}\nexport interface Table {\n    /**\n     * The name of the table.\n     */\n    name: string;\n    /**\n     * The raw SQL schema dump for the table.\n     * Null if configured to not dump.\n     */\n    schema: string | null;\n    /**\n     * The raw SQL data dump for the table.\n     * Null if configured to not dump.\n     */\n    data: string | null;\n    /**\n     * The list of column definitions for the table.\n     */\n    columns: ColumnList;\n    /**\n     * An ordered list of columns (for consistently outputing as per the DB definition)\n     */\n    columnsOrdered: Array\u003cstring\u003e;\n    /**\n     * True if the table is actually a view, false otherwise.\n     */\n    isView: boolean;\n    /**\n     * A list of triggers attached to the table\n     */\n    triggers: Array\u003cstring\u003e;\n}\nexport interface DumpReturn {\n    /**\n     * The result of the dump\n     */\n    dump: {\n        /**\n         * The concatenated SQL schema dump for the entire database.\n         * Null if configured not to dump.\n         */\n        schema: string | null;\n        /**\n         * The concatenated SQL data dump for the entire database.\n         * Null if configured not to dump.\n         */\n        data: string | null;\n        /**\n         * The concatenated SQL trigger dump for the entire database.\n         * Null if configured not to dump.\n         */\n        trigger: string | null;\n    };\n    tables: Array\u003cTable\u003e;\n}\nexport default function main(inputOptions: Options): Promise\u003cDumpReturn\u003e;\n\nexport as namespace mysqldump;\n```\n\n---\n\nThe MIT [License](./LICENSE.md)\n\n## Contributing\n\n### Local Installation\n\nMake sure to first install all the required development dependencies:\n\n```shell\nyarn\n// or\nnpm install .\n```\n\n### Linting\n\nWe use [eslint](https://www.npmjs.com/package/eslint) in conjunction with [typescript-eslint-parser](https://www.npmjs.com/package/typescript-eslint-parser) for code linting.\n\nPRs are required to pass the linting with no errors and preferrably no warnings.\n\n### Testing\n\nTests can be run via the `test` script - `yarn test` / `npm test`.\n\nAdditionally 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`.\n\nPRs are required to maintain the 100% test coverage, and all tests must pass successfully.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradzacher%2Fmysqldump","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbradzacher%2Fmysqldump","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradzacher%2Fmysqldump/lists"}