简体   繁体   English

在Node.js中导出和导入SQL DB

[英]Export and import SQL DB in Node.js

I need to export MySQL database from public server and import it to development one after every content change and I'm trying to automate it with node.js. 我需要从公共服务器导出MySQL数据库,然后在每次更改内容后将其导入到开发数据库中,而我正在尝试使用node.js使其自动化。 Is there any out of the box solution to generate .sql file like one created by phpmyadmin but without php or MySQL CLI? 是否有任何开箱即用的解决方案来生成.sql文件,如由phpmyadmin创建的但没有php或MySQL CLI的解决方案?

I've used the mysqldump node.js package before 我之前使用过mysqldump node.js包

From their documentation: 从他们的文档中:

var mysqlDump = require('mysqldump');

mysqlDump({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'test',
    dest:'./data.sql' // destination file 
},function(err){
    // create data.sql file; 
})

This generates the .sql file - it's up to you where to put it / what to do with it however. 这将生成.sql文件-它取决于您将文件放置在何处/如何处理。

I wouldn't recoment mysqldump because it produces too big a file. 我不会推荐mysqldump,因为它会产生太大的文件。 My phpMyadmin file was 5MB while mysqldump gave me 15MB. 我的phpMyadmin文件是5MB,而mysqldump给了我15MB。 My DB size was small but for big data this could be a problem. 我的数据库大小很小,但是对于大数据来说,这可能是个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM