如何在linux上用ODBC连接数据库 | How to connect database on Linux by ODBC

Step 1: install freetds, unixODBC:

yum install freetds unixODBC

Step 2: config freetds.conf, add below:

[steemDB]
host = sql.steemsql.com
port = 1433
tds version = 8.0

Step 3: config odbcinst.ini, add below:

[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/libtdsodbc.so
Setup = /usr/lib/libtdsS.so
UsageCount = 1

Step 4: config odbc.ini, add below:

[steemDB]
Description = MSSQL Server
Driver = freetds
Database = DBSteem
ServerName = steemDB
TDS_Version = 8.0

Step 5: install luasql:

luarocks install luasql-odbc

Step 6: test the config with below lua code:

luasql = assert (require "luasql.odbc")
env = assert(luasql.odbc())
con = assert (env:connect ("steemDB","steemit","steemit"))
cur = assert (con:execute ("select voting_power from Accounts where name='alanzheng'" ))
row = cur:fetch ({}, "voting_power")
while row do
table.foreach (row, print)
row = cur:fetch (row, "voting_power")
end
cur:close()
con:close()
env:close()

Result:

1       8027
Last modified: le 2018/11/02 02:12