Hello!
2013/11/5 rockiee281:
> 我们现在在线上使用的是ngx_openresty/1.2.6.6,最近在用drizzle做一些数据的插入操作发现了一些疑惑。数据在插入的时候报错了,因为某个字段超长,“Data
> too long for column 'data' at row 1 while sending query to drizzle
> upstream”,但是返回res的status却是200。
> 那是不是只要连接数据库并操作成功,状态就是200呢?
在这种情况下 ngx_drizzle 产生的是 500 的错误码,而不是 200。请看下面这个最小化的完整示例:
upstream backend {
drizzle_server 127.0.0.1:3306 protocol=mysql
dbname=ngx_test user=ngx_test password=ngx_test;
#drizzle_keepalive max=10 overflow=ignore mode=single;
}
server {
listen 8080;
location = /mysql {
drizzle_pass backend;
drizzle_query "insert into cats (name) values ('hello world!')";
rds_json on;
}
}
同时我们在 MySQL 一侧事先创建好下面这个 cats 表:
CREATE TABLE cats (id integer, name varchar(1))
同时在 MySQL 自己的 /etc/my.cnf 配置文件中的 [mysqld] 下面配置好下面这一行:
sql-mode="STRICT_ALL_TABLES"
然后我们启动 nginx 并访问上面定义的 /mysql 这个接口:
$ curl -i localhost:8080/mysql
HTTP/1.1 500 Internal Server Error
Server: nginx/1.4.3
Date: Wed, 06 Nov 2013 05:11:29 GMT
Content-Type: text/html
Content-Length: 202
Connection: close
<html>
<head><title>500 Internal Server Error</title></head>
<body bgcolor="white">
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx/1.4.3 (no pool)</center>
</body>
</html>
我们可以看到确实是 500 错误码和 500 错误页。
Nginx 错误日志文件中也出现了和你一样的 mysql 错误消息:
$ grep error logs/error.log
2013/11/05 21:11:29 [error] 11281#0: *5 failed to send query: 17
(1406): Data too long for column 'name' at row 1 while sending query
to drizzle upstream, client: 127.0.0.1, server: localhost, request:
"GET /mysql HTTP/1.1", upstream: "drizzle://127.0.0.1:3306", host:
"localhost:8080"
我这里使用的 ngx_drizzle、ngx_rds_json 和 nginx 的版本和最新的 ngx_openresty 主线版 1.4.3.1 完全一致。
另外,值得一提的是,推荐总是使用最新的 ngx_openresty 主线版或者稳定版。
Best regards,
-agentzh
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 openresty@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html