lua mysql quickstart
<p>Here is the tutorial to write and build Lua application that can communicate with MySQL database.</p>
Dependency Installation
At first, we need to install LuaRocks. Here is the tutorial.
We need to install dependency to access MySQL database through Lua. Execute the command to install dependency:
1 | luarocks install luasql-mysql MYSQL_INCDIR=/usr/include/mysql/ |
But default dependency miss some libraries or variables. In that case, we need to use different source:
1 | luarocks --from=http://rocks.luarocks.org/dev install luasql-mysql cvs-1 MYSQL_INCDIR=/usr/include/mysql |
Sample Code
Below is the sample code to do MySQL query. The file name is mysql.lua:
1 | luasql = require "luasql.mysql" |
Then execute above lua script using following command:
1 | lua mysql.lua |
</div>
<footer>
<div class="alignright">
<a href="javascript:void(0)" class="share-link bdsharebuttonbox" data-cmd="more">Share</a>
</div>
<div class="clearfix"></div>
</footer>