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报错笔记的更多相关文章

  1. YII报错笔记:<pre>PHP Notice &#039;yii\base\ErrorException&#039; with message &#039;Uninitialized string offset: 0&#039; in /my/test/project/iot/vendor/yiisoft/yii2/base/Model.php:778

    YII常见报错笔记 报错返回的代码如下: <pre>PHP Notice 'yii\base\ErrorException' with message 'Uninitialized str ...

  2. iOS报错笔记

    问题一: linker command failed with exit code 1 (use -vto see invocation) 原因:导入了.m的头文件,导致同时有两个一样的.m文件在编译 ...

  3. iOS项目之报错笔记

    问题一: linker command failed with exit code 1 (use -vto see invocation) 原因:导入了.m的头文件,导致同时有两个一样的.m文件在编译 ...

  4. angular 报错笔记

    1.错误信息: Failed to instantiate module app due to: Error: [$injector:unpr] http://errors.angularjs.org ...

  5. SpringBoot报错笔记

    异常一: 1.访问所有方法路径都返回一个page: 截图: 出错原因:不知道 解决方法:新建项目 异常二: 提交表单信息报错 原因:映射文件和和表单的提交方式不统一 解决方法:统一方式即可: 错误三: ...

  6. Django启动报错笔记

    NO.1: You have 15 unapplied migration(s). Your project may not work properly until you apply the mig ...

  7. Vue报错笔记

    1.错误信息:[Vue warn]: Property or method "object" is not defined on the instance but referenc ...

  8. 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 ...

  9. 解决springmvc报错,java.lang.IllegalArgumentException:No converter found for return value of type: class .......

    1.背景 最近在自学java中的三大框架 ssm,在 springmvc 与 mybatis 整合过程中用到 json 数据交互.因为看的视频的是比较早的嘛,一些配置.jar包什么的,要么跟 jdk ...

  10. go语言,golang学习笔记3 用命令下载框架报错问题解决 设置环境变量

    go语言,golang学习笔记3 用命令下载框架报错问题解决 设置环境变量 下载安装:go get github.com/astaxie/beego 首页 - beego: 简约 & 强大并存 ...

随机推荐

  1. 在.NET后端开发的十年之旅:反思与总结

    开局        依稀记得那是2014年11月大四上学期,学校已经没有课了.看着同寝室的其他室友都出去实习了,而我一个人还坐在电脑前发呆.因为的不敢出去面试. 由于小学时牙齿有一颗龅牙,从小就产生了 ...

  2. Android 国际化:新增越南语语系(Java)

    前提: 1. 在res文件夹中,新增values-vi文件夹(越南语文件夹) 2. 在步骤1的文件夹中,新增strings.xml 背景: 1. targetSdkVersion 29 2. Jdk ...

  3. docker stop 容器,连接被拒绝

    docker stop 容器ID 报错,无法kill,连接被拒绝 经过网上查找以及实际情况,发现原因为: 服务器重启时,正在运行的docker内的容器正在进行处理, 因为docker没有提前关闭,导致 ...

  4. 【YashanDB数据库】yasql登录有特殊字符@导致无法登录

    问题备机 Linux bash shell环境下,使用yasql登录数据库没有使用转义导致登录失败.报错信息如下 问题分析 linux特殊字符转义问题,多加几层转义可以解决问题. 解决办法 su - ...

  5. P3792 由乃与大母神原型和偶像崇拜

    题意 给定长为 \(n\) 的数组 \(a\),支持单点修改,\(q\) 次查询区间 \([l,r]\) 是否可以重排为值域上连续的一段. \(n,q\le5\times10^5,a_i\le2.5\ ...

  6. 编译和分发 Chez Scheme 应用程序

    参考 Building and Distributing Applications. 假设源码由两个文件组成,A.ss 和 B.ss,其中 A.ss 依赖 B.ss.下面我们将其编译为可供分发的二进制 ...

  7. C++:使自定义类支持迭代器

    概述 在 C++ 中,链表迭代器是一种用来遍历链表(如 std::list)元素的工具.链表是一种数据结构,其中每个元素(节点)包含一个数据值和一个指向下一个节点的指针.链表迭代器允许以类似于数组的方 ...

  8. anaconda-navigator 卡在 loading applications

    其实上学期开学就已经这样了,我又不用,再者我上课对这些依赖不大,就没管. 这几天想彻底搞定吧.现状了opencv,最后搞了半天,还是通过安装相应版本的.whl文件搞定了,无法conda install ...

  9. C语言位域的内存布局

    本文将先粗略介绍大小端,和大小端的测试方法,最后介绍位域的内存布局. 1. 大小端 大端模式,是指数据的高字节保存在内存的低地址中,而数据的低字节保存在内存的高地址中. 小端模式,是指数据的高字节保存 ...

  10. ServiceMesh 2:控制面和数据面的职责(图文总结)

    ★ ServiceMesh系列 1 Service Mesh介绍 之前的章节我们详细介绍了ServiceMesh的基础知识. ServiceMesh 是最新一代的微服务架构,作为一个基础设施层,能够与 ...