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
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
// setup odbc.ini
//Driver = SQL Server Native Client 11.0
//Description = Microsoft SQL Server ODBC Driver V1.0 for Linux
//SERVER = 18.104.22.168
//Database = vpdsqldev
//user = VPD
//port = 3306
To test if it works, we can use below commands:
sqlcmd -S22.214.171.124 -ddb_name -Uuser_name -Q “select * from xxx”
You can also write c logic to connect by ODBC:
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/
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.