使用Sequelize在MySQL中插入大Blob

时间:2018-08-01 08:34:36

标签: mysql sequelize.js

我正在尝试使用Sequelize.js在Mysql数据库中插入一个大Blob。

Sequelize.query(`INSERT INTO documents (document, creationDate, modificationDate) VALUES ('${document}', '2018-07-31 14:44:06', '2018-07-31 14:44:06')`);

document fs.readFileAsync()

的输出

插入大小小于或等于2097066字节的大小文件没有任何问题。但是,如果我在文件中添加单个字符,则会系统地得到此错误:

  

{“数据”:{“消息”:“正在执行(默认):插入documentsiddocumentfileNamecreationDatemodificationDate)值(DEFAULT,X'efb [...] 0d0a','tooBig.txt','2018-08-01 08:28:26','2018-08-01 08:28 :26');“,” stack“:” SequelizeDatabaseError:在Query.formatError(C:\ Users \ me \ dev \ uploader \ node_modules \ sequelize \ lib \ dialects \ mysql \ query.js:175中读取ECONNRESET \ n: 14)\ n在查询处(C:\ Users \ me \ dev \ uploader \ node_modules \ sequelize \ lib \ dialects \ mysql \ query.js:49:21)\ n在查询处(C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ Connection.js:502:10)\ n在Query._callback(C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ Connection.js:468:16) \ n在Query.Sequence.end(C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ protocol \ sequences \ Sequence.js:83:24)\ n在Protocol.handleNetworkError(C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ protocol \ Protocol.js:361:14)\ n位于Connection._handleNetworkError(C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ Connection.js: 420:18)\ n在emitOne(events.js:116:13)\ n在Socket.emit(events.js:211:7)\ n在emitErrorNT(内部/流/destroy.js:64:8)\n在_combinedTickCallback(内部/进程/next_tick.js:138:11)\n process._tickCallback(内部/进程/next_tick.js:180:9)“}}}   未处理的拒绝SequelizeConnectionError:致命错误后无法排队退出。       在退出。 (C:\ Users \ me \ dev \ uploader \ node_modules \ sequelize \ lib \ dialects \ mysql \ connection-manager.js:136:30)       在退出。 (C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ Connection.js:502:10)       在Quit._callback(C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ Connection.js:468:16)       在Quit.Sequence.end(C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ protocol \ sequences \ Sequence.js:83:24)       在Quit.end(C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ protocol \ sequences \ Quit.js:24:28)       在C:\ Users \ me \ dev \ uploader \ node_modules \ mysql \ lib \ protocol \ Protocol.js:224:14       在_combinedTickCallback(内部/进程/next_tick.js:131:7)       在process._tickCallback(internal / process / next_tick.js:180:9)

如何解决此错误,或者此错误来自何处?

编辑

我终于找到了解决方法:

在您的mysql配置中将 max_allowed_pa​​cket 设置为16M(或更高)

0 个答案:

没有答案