openresty / lua-resty-mysql

Nonblocking Lua MySQL driver library for ngx_lua or OpenResty
708 stars 236 forks source link

腾讯云服务器上mysql,使用lua不能访问数据库 #110

Open ACEandMy opened 4 years ago

ACEandMy commented 4 years ago

ngx.header.content_type="application/json;charset=utf8" local cjson = require("cjson") local mysql = require("resty.mysql") local uri_args = ngx.req.get_uri_args() local id = uri_args["id"] local db,err = mysql:new() if not db then ngx.say("failed to instantiate mysql: ",err) return end db:set_timeout(1000) local ok,err,errno,sqlstate = db:connect(){ host = "127.0.0.1", port = 3306, database = "changgou_content", user = "root", password = "123456" } if not ok then ngx.say("failed to connect: ", err, ": ", errno, " ", sqlstate) return end local select_sql = "select url,pic from tb_content where status ='1' and category_id="..id.." order by sort_order" res,err,errno,sqlstate = db:query(select_sql) if not res then ngx.say("bad result: ", err, ": ", errno, ": ", sqlstate, ".") return end db:close() local redis = require("resty.redis") local red = redis:new() red:settimeout(2000) local ip ="127.0.0.1" local port = 6379 red:connect(ip,port) red:set("content"..id,cjson.encode(res)) red:close()

浏览器访问:提示 failed to connect: Client does not support authentication protocol requested by server; consider upgrading MySQL client: 1251 08004

fc13240 commented 3 years ago

请尝试更新 mysql开发版本库,如果是centos系统,请以下文章参考更新:https://www.tech-field.org/articles/2021/01/04/1609752680599.html

Surrin1999 commented 2 years ago

请尝试更新 mysql开发版本库,如果是centos系统,请以下文章参考更新:https://www.tech-field.org/articles/2021/01/04/1609752680599.html

我也遇到了这个问题,至今没解决