PYTHON3.X:PYODBC+FREETDS+UNIXODBC Connecting the Sybase database (Linux system)

Source: Internet
Author: User
Tags locale odbc sybase sybase database

PYTHON3.X:PYODBC+FREETDS+UNIXODBC Connecting a Sybase database (Linux system), installing UNIXODBC, and dependent packages
Yum-y install gcc gcc-c++ unixodbc unixodbc-devel  python-devel
Second, installation FreeTDS
Tar XF freetds-stable.tgzcd freetds-0.91/. /configure--prefix=/usr/local/freetds--with-unixodbc=/usr/--with-tdsver=5.0
Iii. configuring FreeTDS and using TSQL to test the connection
vi/usr/local/freetds/etc/freetds.conf#Add the following content:[Sybase] host=IP Address Port=Port number TDS version= 5.0Client CharSet= UTF-8#specific IP and port number to be replaced by individual#To test the connection:/usr/local/freetds/bin/tsql-s sybase-u User Name-P Password#If the following appears, or something like this, indicates a successful connection, you can execute some SQL statements to tryLocale is "En_us.utf8"Locale CharSet is "UTF-8"using default CharSet"UTF-8"1>
Iv. configuration unixodbc and test isql
#Create the driver template file 1.txt content as follows:[Tds]description=Sybasesetup=/usr/lib/libtdss.sodriver64=/usr/local/freetds/lib/Libtdsodbc.sodriver=/usr/local/freetds/lib/Libtdsodbc.sosetup64=/usr/lib64/Libtdss.sofileusage= 1Usagecount= 2#then use Odbcinst to install the driver:Odbcinst-i-d-f 1. txt#after the execution, you can check the/etc/odbcinst.ini, if you can see the contents of the TDS, the configuration is not a problem#You can also check the drive with Odbcinst-q-D#Create a template file for the data source with the following contents:[Xiaosu]driver=tdsdescrption=Sybase Servertrace=Noserver=IP Address Database=Database Port=Port number#the DATABASE,IP address and port number are replaced with the one you need.Odbcinst-i-s-f 2. txt#after execution, the. odbc.ini file is generated in the user's home directory, and vim ~/.odbc.ini check the file contents. You can also check for available data sources with odbcinst-q-s#Test connection with isql: isql-v xiaosu user name password#If the following appears, the connection is successful. +---------------------------------------+|                            connected!                                       || || sql-statement | | Help [TableName] | |                                       Quit | | |+---------------------------------------+SQL>
V. Compile and install PYODBC
Unzip pyodbc-3.0.7. zip cd pyodbc-3.0.7python setup.py install
Six, test PYODBC connection
Import pyodbcconn=pyodbc.connect ("Dsn=xiaosu; Uid=uid;pwd=password") Cursor=conn.cursor ()# output All table names in the database Cursor.execute ("select name from sysobjects where type = ' U '")for   in cursor:    print(i)

PYTHON3.X:PYODBC+FREETDS+UNIXODBC Connecting the Sybase database (Linux system)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.