luasql报错笔记
luasql 编译安装
查看mysql配置,注意 lmysqlclient 路径
[root@hmy luasql-master]# yum install mysql-devel gcc* -y
[root@hmy luasql-master]# mysql_config
Usage: /usr/bin/mysql_config [OPTIONS]
Options:
--cflags [-I/usr/include/mysql]
--include [-I/usr/include/mysql]
--libs [-L/usr/lib64/mysql -lmysqlclient -lpthread -lz -lm -lssl -lcrypto -ldl]
--libs_r [-L/usr/lib64/mysql -lmysqlclient -lpthread -lz -lm -lssl -lcrypto -ldl]
--plugindir [/usr/lib64/mysql/plugin]
--socket [/var/lib/mysql/mysql.sock]
--port [0]
--version [5.5.56]
--libmysqld-libs [-L/usr/lib64/mysql -lmysqld]
--variable=VAR VAR is one of:
pkgincludedir [/usr/include/mysql]
pkglibdir [/usr/lib64/mysql]
plugindir [/usr/lib64/mysql/plugin]
修改luasql-master安装包里的config
PREFIX ?= /usr/local/apisix/deps
LUA_SYS_VER ?= 5.1
LUA_LIBDIR ?= $(PREFIX)/lib/lua/$(LUA_SYS_VER)
LUA_DIR ?= $(PREFIX)/share/lua/$(LUA_SYS_VER)
LUA_INC ?= $(PREFIX)/include
...
...
DRIVER_LIBS_mysql ?= -L/usr/lib64/mysql -lmysqlclient -lz
DRIVER_INCS_mysql ?= -I/usr/include/mysql
...
...
安装luasql-mysql
[root@hmy luasql-master]# make mysql
gcc -O2 -std=gnu99 -Wall -Wmissing-prototypes -Wmissing-declarations -pedantic -fPIC -I/usr/local/apisix/deps/include -DLUASQL_VERSION_NUMBER='"2.6.0"' -c src/luasql.c -o src/luasql.o
gcc -O2 -std=gnu99 -Wall -Wmissing-prototypes -Wmissing-declarations -pedantic -fPIC -I/usr/local/apisix/deps/include -DLUASQL_VERSION_NUMBER='"2.6.0"' src/ls_mysql.c -o src/mysql.so -shared src/luasql.o -I/usr/include/mysql -L/usr/lib64/mysql -lmysqlclient -lz
[root@hmy luasql-master]# make install
mkdir -p /usr/local/apisix/deps/lib/lua/5.1/luasql
cp src/*.so /usr/local/apisix/deps/lib/lua/5.1/luasql
安装完成后,执行apisix reload,报错内容如下:
2022/09/19 00:22:50 [error] 119935#119935: *11035303 [lua] plugin.lua:103: load_plugin(): failed to load plugin [sfimplat-auth] err: attempt to index a nil value, context: init_worker_by_lua*
2022/09/19 00:22:50 [error] 119933#119933: *11035302 [lua] plugin.lua:103: load_plugin(): failed to load plugin [sfimplat-auth] err: attempt to index a nil value, context: init_worker_by_lua*
一开始我以为是安装问题,反复检查重复安装很久才发现,是局部变量、全局变量问题
例如:
[root@hmy luasql]# lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> require "luasql.mysql"
> local luasql = require("luasql.mysql")
> local env = assert(luasql.mysql())
stdin:1: attempt to index global 'luasql' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: ?
但如果这样写就没问题了
local luasql = require("luasql.mysql")
env = assert(luasql.mysql())
--连接数据库
conn = env:connect("数据库名","用户名","密码","IP地址",端口)
--设置数据库的编码格式
conn:execute"SET NAMES UTF8"
--执行数据库操作
cur = conn:execute("select * from tb_users where username='test'")
row = cur:fetch({}, "a")
core.log.error(core.json.encode(row))
或者 写在局部方法里,这样就可以用局部变量了
local function mysql_query(roles)
local env = assert(luasql.mysql())
local conn = env:connect("数据库名","用户名","密码","IP地址",端口)
local per_dict = {}
local cmd = string.format("select * from tb_roles where code like '%test%'")
local cursor, err = conn:execute(cmd)
local row = cursor:fetch({}, 'a')
table.insert(per_dict, row.url)
while row do
-- reusing the table of results
row = cursor:fetch(row, "a")
if row then
table.insert(per_dict, row.url)
end
end
conn:close() --关闭数据库连接
env:close() --关闭数据库环境
return per_dict
end
``
luasql报错笔记的更多相关文章
- YII报错笔记:<pre>PHP Notice 'yii\base\ErrorException' with message 'Uninitialized string offset: 0' in /my/test/project/iot/vendor/yiisoft/yii2/base/Model.php:778
YII常见报错笔记 报错返回的代码如下: <pre>PHP Notice 'yii\base\ErrorException' with message 'Uninitialized str ...
- iOS报错笔记
问题一: linker command failed with exit code 1 (use -vto see invocation) 原因:导入了.m的头文件,导致同时有两个一样的.m文件在编译 ...
- iOS项目之报错笔记
问题一: linker command failed with exit code 1 (use -vto see invocation) 原因:导入了.m的头文件,导致同时有两个一样的.m文件在编译 ...
- angular 报错笔记
1.错误信息: Failed to instantiate module app due to: Error: [$injector:unpr] http://errors.angularjs.org ...
- SpringBoot报错笔记
异常一: 1.访问所有方法路径都返回一个page: 截图: 出错原因:不知道 解决方法:新建项目 异常二: 提交表单信息报错 原因:映射文件和和表单的提交方式不统一 解决方法:统一方式即可: 错误三: ...
- Django启动报错笔记
NO.1: You have 15 unapplied migration(s). Your project may not work properly until you apply the mig ...
- Vue报错笔记
1.错误信息:[Vue warn]: Property or method "object" is not defined on the instance but referenc ...
- Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again YUM报错
1.挂盘 ----- 2.# mount /dev/sr0 /media/ mount: block device /dev/sr0 is write-protected, mounting ...
- 解决springmvc报错,java.lang.IllegalArgumentException:No converter found for return value of type: class .......
1.背景 最近在自学java中的三大框架 ssm,在 springmvc 与 mybatis 整合过程中用到 json 数据交互.因为看的视频的是比较早的嘛,一些配置.jar包什么的,要么跟 jdk ...
- go语言,golang学习笔记3 用命令下载框架报错问题解决 设置环境变量
go语言,golang学习笔记3 用命令下载框架报错问题解决 设置环境变量 下载安装:go get github.com/astaxie/beego 首页 - beego: 简约 & 强大并存 ...
随机推荐
- 使用 nuxi info 查看 Nuxt 项目详细信息
title: 使用 nuxi info 查看 Nuxt 项目详细信息 date: 2024/9/5 updated: 2024/9/5 author: cmdragon excerpt: 摘要:文章介 ...
- 6.9找回机制接口安全&验证码token接口
响应包response burp截取拦截,改相应包: 思路:此处应该若是修改密码,先抓到修改成功数据包(截取验证关键字),在替换为需要绕过的数据包,截取response数据包,修改验证成功关键字达到绕 ...
- Linux 终端运行命令时出现多行带有加号的信息(详见文章内容)
++_vte_ prompt_ command +++ HISTTIMEFORMAT= +++ history 1 +++ sed 's/^ *[0-9] \+ *//' ++ local ' com ...
- Splay/LCT 学习笔记
唔,其实我不会 Splay,但是我会 LCT. 众所周知,会 LCT 和会 Splay 是两回事,因为 LCT 只需要旋至根即可. 到现在还是不会,但是先把 LCT 的 Splay 写一下吧. 自己复 ...
- PHP 程序员学会了 Go 语言就能唬住面试官吗?
大家好,我是码农先森. 唬住了 50k ,唬不住就 5k .这句话一直是 PHP 程序员之间相互吹捧.吹牛逼的笑点,每次面试过后都会挠挠头上仅剩的几根头发,回想自己是否吹牛逼会过了头.我经常在微信程序 ...
- Qt 中实现异步散列器
[写在前面] 在很多工作中,我们需要计算数据或者文件的散列值,例如登录或下载文件. 而在 Qt 中,负责这项工作的类为 QCryptographicHash. 关于 QCryptographicHas ...
- ASP.NET Core – Globalization & Localization
前言 之前就写过 2 篇, 只是写的很乱, 这篇作为整理版. Asp.net core (学习笔记 路由和语言 route & language) Asp.net core 学习笔记之 glo ...
- HTML & CSS – Responsive Image 响应式图片 (完整版)
前言 之前就有写过关于 Retina 和 Responsive Image 响应式图片 (responsive image) Retina 显示屏 但写的太烂了, 所以有了后来的 屏幕, 打印, 分辨 ...
- 月薪20k以上的软件测试工程师的必备知识点?全部拿走吧!
我们都知道作为一个软件测试工程师,入门相对比较简单,但是要达到技术精通,甚至薪资能达到20k以上的话,那绝对需要对测试开发有一个系统的了解,以及对这些系统的知识能够熟练掌握. 今天的话是我从阿里以为做 ...
- Git 本地仓库与基础操作指令
本地仓库 获取本地仓库 在电脑任意位置创建一个空目录(例如test)作为我们的本地Git仓库 进入这个目录中,右键打开Git Bash窗口 执行 git init命令 如果创建成功后可在文件夹下看到隐 ...