Python操作MySql

一、linux客户端连接mssql server
1.linux下安装unixODBC
 
 
2.linux安装FreeTDS
(1) 配置FreeTDS。 /etc/freetds/freetds.conf
[egServer70]
host = server ip
port = 1433
tds Version = 7.0
[dsnName]
host = server ip
port = 1433
tds Version = 8.0
client charset = UTF-8
 
(2)配置odbc /etc/odbc.ini
[dsnName]
Driver = FreeTDS
Description = Odbc connection via FreeTDS
Trace = No
Servername = dsnName
Database = oneicdb
(3)配置odbc /etc/odbc
[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
FileUsage = 1
CPTimeout =
CPResure =
client charset = utf-8
UsageCount = 1
[SQL Server]
Description = FreeTDS ODBC driver for MSSQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
FileUsage = 1
 
 
 
 
import pyodbc 
strconn= 'DRIVER={SQL Server};SERVER=.;DATABASE=test;UID=sa;PWD=sa'  
db = pyodbc.connect(strconn)  
c = db.cursor()
sql = '.....................'
c.execute(sql)
c.fetchone()
c.fetchall()
c.close()
db.close()
 
 
 
存储过程调用:c.execute("{call sp_MemberAdrInsert_py (?,?,?,?,?,?,?,?,?,?)}", ('a','b','c','d','e','f','g','h','100086',0))
 
1、存储过程可以直接返回值,如果返回一个值,那么存储过程里必须有:SET NOCOUNT ON
2、存储过程不可以output值
posted @ 2018-05-18 11:58  James·Sean  阅读(813)  评论(1编辑  收藏  举报