mysql - Nodejs/Nginx 服务器(AWS)/Mysql/insert 502 Bad Gateway 错误

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

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

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

只有 insert case 是错误的(select, update, delete 都运行良好。)

如果我尝试插入本地主机,它运行良好。

<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)

最佳答案

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

试试这个:

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

关于mysql - Nodejs/Nginx 服务器(AWS)/Mysql/insert 502 Bad Gateway 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39228714/

相关文章:

amazon-web-services - 具有 Cognito 联合身份的 AWS AppSync IAM 授权

PHP从Assoc数组中获取字符串值并将其转换为字符串进行比较

python - Lambda 代理响应格式错误 : deploying python endpoints through serverless

mysql - 如何处理并发(多个用户编辑相同数据)- VB.NET 特色 MySQL

node.js - AWS Lambda 制作视频缩略图

javascript - 如何使用 rsa 公钥验证文件

node.js - 基于性能、稳定性和 ES8+ 支持的 Knex 与 mysql2

amazon-web-services - 在使用 Kitchen 和 Chef 进行本地开发时,您如何模拟 OpsWorks 特定的服务/依赖项?

php - 具有未加载附加列的 Kohana 数据透视表

mysql - 合并两个 SQL 查询