• 系统:Ubuntu 18.04
  • python版本:python3.6.9
  • 数据库:sybase

安装软件包

sudo apt update
sudo apt-get install python3-dev
sudo apt-get install unixodbc-dev
sudo apt install python-pyodbc-dbg
sudo apt-get install -y freetds-bin
sudo apt-get install freetds-dev tdsodbc
pip3 install pyodbc

编辑配置文件:

sudo vi /etc/odbcinst.ini
[FreeTDS]
Description=FreeTDS Driver
#Driver=/usr/lib/odbc/libtdsodbc.so
Setup=/usr/lib//x86_64-linux-gnu/odbc/libtdsS.so
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

编辑python连接sybase的代码:

vi connectSybase.py
import pyodbc
serv = 'DBIpAddr'
usr = 'username'
passwd = 'password'
db = 'yourdb'
prt = 4100
driver="FreeTDS"


sql='''your sql senetences
'''


conn = pyodbc.connect(driver=driver, server=serv, database=db,port = prt,
                  uid=usr, pwd=passwd)
print(conn)
cursor = conn.cursor()
cursor.execute(sql)
row = cursor.fetchall()
print(row)

参考:

https://stackoverflow.com/questions/12031897/missing-libtdsodbc-so-in-freetds-dev-mssql-on-ubuntu

https://stackoverflow.com/questions/47180843/python-cant-open-lib-libtdsodbc-so-file-not-found

https://stackoverflow.com/questions/52418707/connect-to-sybase-data-base-using-python-3-6-and-pymssql


如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!



0 条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注