--[[
luarocks lua语言的包管理器
luasql https://luarocks.org/
brew install luarocks
luarocks install luasql-mysql 注意此处,如果你是 mariadb,然后要求指定 MYSQL_DIR 参数的时候,
千万不要指到 mariadb 的安装目录,而是要指到一个真正的mysql 安将目录
那是不是不能用 mariadb 呢,也不是,要手动安装一遍
luarocks install luasql-sqlite3
luarocks install luasql-postgres
luarocks install luasql-mysql
luarocks install luasql-sqlite
luarocks install luasql-odbc
]]--
local luasql = require("luasql.mysql");
client = luasql.mysql();
--创建连接
conn=client:connect("lua-test","root","12345678","127.0.0.1",3306); --数据库名,用户名,密码,IP,端口
if conn == nil then
print("连接失败");
os.exit();
end
--select
rs=conn:execute("select * from user_list order by id desc");
row = rs:fetch({},"a");
while row do
print(row.id,row.name,row.age);
row = rs:fetch(row,"a");
end
--insert
--rs=conn:execute("insert into user_list (name,age)values('def',456)");
--print(rs);
--update
rs=conn:execute("update user_list set name='DEF',age=789 where id<=4");
print(rs);
--delete
rs=conn:execute("delete from user_list where id=4");
print(rs);
conn:close();
client:close();
Lua + mysql 实战代码
HuntFalcon2023-08-20 14:58
相关推荐
这个DBA有点耶1 天前
SQL改写进阶:标量子查询的“隐形代价”与消除实战smallyoung1 天前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南数据技术说1 天前
MySQL 迁移实战——如何实现真正的"零改造"平滑切换唐青枫5 天前
MySQL JSON 实战详解:从存储、查询、更新到 JSON_TABLE 与索引小满8785 天前
5.Mysql事务隔离级别与锁机制元Y亨H6 天前
技术笔记:MySQL 字符集排序规则与大小写敏感性问题解决方案这个DBA有点耶7 天前
GROUP BY优化全解:如何写出既不丢数据又飞快的分组查询掉头发的王富贵7 天前
【StarRocks】极限十分钟入门StarRocksSamDeepThinking7 天前
一条UPDATE语句在MySQL 8.0中到底加了几把锁?李白客9 天前
KES新版MySQL兼容能力再升级意味着什么?