mysqlDump({
host: hostname,
port: portname,
user: username,
password: password,
database: datbasename,
dest: /directory,
}, function (err) {
console.log(err)
});
这是我的代码,适用于较小的mysql文件。
{
"name": "projectname",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "nodemon ./bin/www"
},
"dependencies": {
"body-parser": "~1.18.2",
"compressing": "^1.2.3",
"cookie-parser": "~1.4.3",
"current-date": "^0.1.1",
"debug": "~2.6.9",
"express": "~4.15.5",
"file-encryptor": "^0.1.1",
"fs": "0.0.1-security",
"fs-extra": "^5.0.0",
"hbs": "~4.0.1",
"monitor-dashboard": "^0.6.7",
"morgan": "~1.9.0",
"mysqldump": "^1.4.2",
"nodemon": "^1.17.2",
"pm2": "^2.10.2",
"promise": "^8.0.1",
"reload": "^2.2.2",
"request": "^2.85.0",
"serve-favicon": "~2.4.5"
},
"config": {
"days_interval": 7,
"max_size": 5242880
}
}
上面给出的是我的package.json文件,所以如果有任何版本问题。
这是弹出的错误。<--最后几个gcs--->
> [5121:0x3e52ce0] 160788 ms: Mark-sweep 1468.6 (1526.4) -> 1468.4
> (1526.9) MB, 1413.3 / 0.0 ms allocation failure GC in old space
> requested [5121:0x3e52ce0] 162286 ms: Mark-sweep 1468.4 (1526.9) ->
> 1468.3 (1495.4) MB, 1497.1 / 0.0 ms last resort GC in old space requested [5121:0x3e52ce0] 163725 ms: Mark-sweep 1468.3 (1495.4) ->
> 1468.3 (1495.4) MB, 1439.7 / 0.0 ms last resort GC in old space requested
==========js堆栈跟踪=========================================
> Security context: 0x3f1c76625529 <JSObject>
> 1: /* anonymous */ [/home/rajesh/vishnu works/dump2/node_modules/mysql/lib/protocol/Protocol.js:~231]
> [pc=0x37a5a37e1095](this=0x35b8ca03d6a1 <Protocol map =
> 0x366e60ff7e71>)
> 2: arguments adaptor frame: 1->0
> 3: write [/home/rajesh/vishnu works/dump2/node_modules/mysql/lib/protocol/Parser.js:~27]
> [pc=0x37a5a37f62c7](this=0x35b8ca03d5e1 <Parser map =
> 0x366e60fecc61>,chunk=0x39cd489b725...
>
> FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap
> out of memory 1: node::Abort() [/usr/local/bin/node] 2: 0x8cea7c
> [/usr/local/bin/node] 3: v8::Utils::ReportOOMFailure(char const*,
> bool) [/usr/local/bin/node] 4:
> v8::internal::V8::FatalProcessOutOfMemory(char const*, bool)
> [/usr/local/bin/node] 5:
> v8::internal::Factory::NewUninitializedFixedArray(int)
> [/usr/local/bin/node] 6: 0xd88283 [/usr/local/bin/node] 7:
> v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**,
> v8::internal::Isolate*) [/usr/local/bin/node] 8: 0x37a5a36042fd}}
现在我可以处理小文件,但大文件会显示此错误。当我把内存增加到更高的值时,这个错误就出现了,并且出现了类似的错误提示,超过了最大行的限制。有人能帮我吗?我真的被这个问题困住了。
1条答案
按热度按时间a64a0gku1#
这个
mysqldump
npm模块有致命的缺陷,永远无法与大型数据库一起工作。它在将任何数据写入文件之前,将数据库转储以字符串的形式完全构造在内存中。如果这比内存大,它将不可避免地崩溃。解决这个问题需要对模块进行一次大的重写,因为它提出了一个非常基本的假设,即转储可以存储在内存中。(它还假设它应该并行地转储所有表,并且应该通过运行一个
SELECT * FROM table
查询每个表。这些假设都不成立。)不要使用此模块。如果需要备份数据库,请使用
mysqldump
命令行工具,或其他备份工具,如mydumper或percona xtrabackup。这些工具都是为处理大型数据库而设计的,并且不受mysqldump
npm模块。