最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NPM MysqlDump and Mysql-Import , how to add option of drop table if exist , Node.js - Stack Overflow

programmeradmin0浏览0评论

I'm using the mysqldump library, and mysql-import. I need to do a restore of my MySQL database, but at the time of doing it, it tells me that you cannot add duplicate files, therefore I manually put DROP TABLE IF EXIST, and it worked and overwritten the database, according to In the Mysqldump documentation there is a way to add the DROP TABLE by default, but I really don't know how to do it, can someone help me?

var mysqldump = require('mysqldump');
const controller = {};


controller.backupDatabase = function(req, res, next) {
  if(mysqldump){
      mysqldump({
          connection: {
              host: 'localhost',
              user: 'root',
              password: '',
              database: 'decoracionesalves',
          },
          dumpToFile: './DecoracionesAlves.sql',
      });
    
  }else{
      //Hacer algo aqui.
  }

};

module.exports = controller;

I'm using the mysqldump library, and mysql-import. I need to do a restore of my MySQL database, but at the time of doing it, it tells me that you cannot add duplicate files, therefore I manually put DROP TABLE IF EXIST, and it worked and overwritten the database, according to In the Mysqldump documentation there is a way to add the DROP TABLE by default, but I really don't know how to do it, can someone help me?

var mysqldump = require('mysqldump');
const controller = {};


controller.backupDatabase = function(req, res, next) {
  if(mysqldump){
      mysqldump({
          connection: {
              host: 'localhost',
              user: 'root',
              password: '',
              database: 'decoracionesalves',
          },
          dumpToFile: './DecoracionesAlves.sql',
      });
    
  }else{
      //Hacer algo aqui.
  }

};

module.exports = controller;
Share Improve this question asked Apr 10, 2021 at 2:53 Adrian AAdrian A 334 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

You can set dropIfExists to true on the schema dump table option.

mysqldump({
  connection: {
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'decoracionesalves',
  },
  dump: { schema: { table: { dropIfExist: true } } },
  dumpToFile: './DecoracionesAlves.sql',
});

See API docs for SchemaDumpOptions

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论