Recently I need build a version of python to run logic to connect remote sql server.
To enable this features in python, we need install below packages:
1. Microsoft SQL Server ODBC Driver V1.0 for Linux. http://www.microsoft.com/en-us/download/details.aspx?id=28160
2. unixodbc
We have to setup odbc ini to make it works:
// set up odbcinst.ini, located in /etc/odbcinst.ini
//[SQL Server Native Client 11.0]
//Description=Microsoft SQL Server ODBC Driver V1.0 for Linux
//Driver=/opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0
//Threading=1
//UsageCount=1
// setup odbc.ini
//[test1]
//Driver = SQL Server Native Client 11.0
//Description = Microsoft SQL Server ODBC Driver V1.0 for Linux
//SERVER = 11.11.1.161
//Database = vpdsqldev
//user = VPD
//port = 3306
To test if it works, we can use below commands:
sqlcmd -S11.11.1.11 -ddb_name -Uuser_name -Q “select * from xxx”
You can also write c logic to connect by ODBC:
#include <sqlext.h>
#include <sql.h>
retcode = SQLConnect(hdbc, (SQLCHAR*) “dsn_name”, SQL_NTS, (SQLCHAR*) “username”, 3, (SQLCHAR*) “password”, 7);
…
Build with below :
// cc -m64 -g -I/usr/include -L/usr/lib64 -lstdc++ -lodbc -oxx xx.c
3. pyodbc. http://code.google.com/p/pyodbc/
download package
run: python setup.py build install // it is based on which python version you want to build on, change the first line in setup.py and python interpretor as well.
For example: there is customized version of python in :/opt/Python3/bin/python3
a), change the first ilne : #!/opt/Python3/bin/python3
b). call : /opt/Python3/bin/python3 setup.py build install
It is easy to install above process.
The reason my process is little complex is because my customized python shell is build with 32-bits
But mysql sql sver ODBCC driver for linux only have 64 bits version.
So I have to migrate my shell to 64 bits.