【问题标题】:Nodejs/ Nginx server(AWS)/ Mysql/ insert 502 Bad Gateway errorNodejs/ Nginx 服务器(AWS)/ Mysql/ 插入 502 Bad Gateway 错误
【发布时间】:2017-01-06 19:27:29
【问题描述】:

当我尝试使用 Mysql、AWS ElasticBeanstalk Nginx 服务器插入一些文本时,

有时会出现 502 Bad Gateway 的错误信息。

只有插入的情况是错误的(选择、更新、删除都很好。)

如果我尝试插入本地主机,它工作得很好。

<form action="/finance" method="post">
	<div class="input-field col l12">
		<input name="consult_name" type="text">
		<input type="submit" value="send">	
	</div>
</form>

router.post('/finance', function(req, res, next) {
	var consult_name = req.body.consult_name;
	console.log(consult_name);
	
	
	var sets = {consult_name : consult_name};
	
	mysql.insert('insert into cider.cid_finance set ?', sets,  function (err, data){

	res.redirect('/finance');
	});
});

2016/08/30 22:04:24 [error] 29838#0: *52 upstream prematurely closed connection while reading response header from upstream, client: 115.95.162.173, server: , request: "POST /finance HTTP/1.1", upstream: "http://127.0.0.1:8081/finance", host: "cidermics.com", referrer: "http://cidermics.com/finance"
2016/08/30 22:04:24 [error] 29838#0: *52 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 115.95.162.173, server: , request: "POST /finance HTTP/1.1", upstream: "http://127.0.0.1:8081/finance", host: "cidermics.com", referrer: "http://cidermics.com/finance"

AWS ElasticBeanstalk 错误日志

/var/app/current/node_modules/mysql/lib/protocol/Parser.js:77
        throw err; // Rethrow non-MySQL errors
        ^

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1
    at Query.Sequence._packetToError (/var/app/current/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
    at Query.ErrorPacket (/var/app/current/node_modules/mysql/lib/protocol/sequences/Query.js:83:18)
    at Protocol._parsePacket (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:280:23)
    at Parser.write (/var/app/current/node_modules/mysql/lib/protocol/Parser.js:73:12)
    at Protocol.write (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/var/app/current/node_modules/mysql/lib/Connection.js:98:28)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:153:18)
    at Socket.Readable.push (_stream_readable.js:111:10)

【问题讨论】:

  • 你使用的是哪个 npm mysql 包?
  • "_from": "felixge/node-mysql", "_id": "mysql@2.10.2",
  • 我无法识别。是这个npmjs.com/package/mysql。似乎解析器错误。尝试插入:mysql.insert('insert into cider.cid_finance set = '+consult_name, function (err, data){ res.redirect('/finance'); });
  • 看看这个:thebittheories.com/… 本文展示了在 aws ubuntu ec2 实例上实现 nodejs 应用程序的方法。关注 The Bit Theories 以获取更多与计算机科学相关的阅读。 :)
  • 它不起作用...实际上 Insert 有 80% 的几率起作用

标签: mysql node.js amazon-web-services nginx


【解决方案1】:

你的 sql 语法是错误的。错误信息明确指出问题出在 mysql 语法。

试试这个:

mysql.insert('insert into cider.cid_finance set consult_name = ?', consult_name,  function (err, data){

【讨论】:

  • 它不起作用...实际上 Insert 有 80% 的几率起作用
  • 发布你现在遇到的错误...也尝试将consult_name包装在一个数组[consult_name]中,并查看文档...github.com/mysqljs/mysql#performing-queries
猜你喜欢
  • 2014-06-28
  • 1970-01-01
  • 2019-03-25
  • 2019-02-26
  • 2018-04-23
  • 2021-01-25
  • 2021-09-11
  • 2018-01-20
  • 2017-05-10
相关资源
最近更新 更多