在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
lua连接数据库可以使用resty.mysql库 示例代码如下: local mysql = require "resty.mysql" local db, err = mysql:new() if not db then ngx.say("failed to instantiate mysql: ", err) return end db:set_timeout(1000) -- 1 sec local ok, err, errcode, sqlstate = db:connect{ host = "10.209.**.**", port = 1234, database = "test", user = "user", password = "123456", charset = "utf8", max_packet_size = 1024 * 1024, } if not ok then ngx.say("failed to connect: ", err, ": ", errcode, " ", sqlstate) return end ngx.say("connected to mysql.")
|
请发表评论