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. vue3+ts Axios封装与使用

    创建完vue3 项目后 新版本:动态控制是否显示加载动画.是否需要判断重复请求.https://www.cnblogs.com/lovejielive/p/17676856.html 一,安装Axio ...

  2. Https通信的SSL证书工作流程原理(转)

    前言 浏览器与服务器之间的https加密通信会包括以下一些概念:非对称加密.对称加密.RSA.证书申请.根证书.https证书加密,就是在传输层tcp和应用层http之间加了一层ssl层来对传输内容进 ...

  3. 专业级语义搜索优化:利用 Cohere AI、BGE Re-Ranker 及 Jina Reranker 实现精准结果重排

    专业级语义搜索优化:利用 Cohere AI.BGE Re-Ranker 及 Jina Reranker 实现精准结果重排 1. 简介 1.1 RAG 在说重排工具之前,我们要先了解一下 RAG. 检 ...

  4. tarjan—算法的神(一)

    本篇包含 tarjan 求强连通分量.边双连通分量.割点 部分, tarjan 求点双连通分量.桥(割边)在下一篇. 伟大的 Robert Tarjan 创造了众多被人们所熟知的算法及数据结构,最著名 ...

  5. C# 开源教程带你轻松掌握数据结构与算法

    前言 在项目开发过程中,理解数据结构和算法如同掌握盖房子的秘诀.算法不仅能帮助我们编写高效.优质的代码,还能解决项目中遇到的各种难题. 给大家推荐一个支持C#的开源免费.新手友好的数据结构与算法入门教 ...

  6. Angular 18+ 高级教程 – 目录

    请按顺序阅读 关于本教程 初识 Angular Get Started Angular Compiler (AKA ngc) Quick View Dependency Injection 依赖注入  ...

  7. Hadoop & Redis未授权漏洞实战——Vulfocus服务攻防

    什么是未授权访问漏洞?Hadoop & Redis靶场实战--Vulfocus服务攻防 一.介绍 未授权访问,也称为未经授权的访问或非法访问,是指在没有得到适当权限或授权的情况下,个人或系统访 ...

  8. map的线程安全,boost库读写锁的实现

       *************** map的线程安全 ********************  *  * 参考1  * map要实现线程安全必须要加锁,如果使用mutex会产生大量的线程等待,可以 ...

  9. 使用BPF之前和之后生成直方图过程的对比

    以bitehist为例: 使用BPF之前: 1.在内核中:开启磁盘IO事件的插桩观测. 2.在内核中,针对每个事件:向perf缓冲区写入一条记录.如果使用了跟踪点技术(推荐方式),记录中会包含关于磁盘 ...

  10. 05-react的类组件和函数组件 -- 状态 state

    // 函数组件是无状态的 既没有数据的 类似 vue 组件中的 data 数据 // 类组件是有状态的组件 是有数据的 是双向绑定的数据 是数据驱动视图的 负责UI的视图更新 (单个组件的私有数据组件 ...