You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
# 一、在m1 mac下使用pyodbc (大坑,需要修改tsl协议版本,不建议使用)
|
|
|
|
|
参考官方文档 https://github.com/mkleehammer/pyodbc/wiki
|
|
|
|
|
```shell
|
|
|
|
|
# 1.安装odbc
|
|
|
|
|
brew update
|
|
|
|
|
brew install unixodbc
|
|
|
|
|
# 2.安装sqlserver linux驱动
|
|
|
|
|
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
|
|
|
|
|
brew update
|
|
|
|
|
HOMEBREW_ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18
|
|
|
|
|
# 3.安装pyodbc
|
|
|
|
|
pip install --no-binary :all: pyodbc
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 查看配置文件路径
|
|
|
|
|
odbcinst -j
|
|
|
|
|
# 输出
|
|
|
|
|
unixODBC 2.3.12
|
|
|
|
|
DRIVERS............: /opt/homebrew/etc/odbcinst.ini
|
|
|
|
|
SYSTEM DATA SOURCES: /opt/homebrew/etc/odbc.ini
|
|
|
|
|
FILE DATA SOURCES..: /opt/homebrew/etc/ODBCDataSources
|
|
|
|
|
USER DATA SOURCES..: /Users/old-tom/.odbc.ini
|
|
|
|
|
SQLULEN Size.......: 8
|
|
|
|
|
SQLLEN Size........: 8
|
|
|
|
|
SQLSETPOSIROW Size.: 8
|
|
|
|
|
# 修改odbcinst.ini
|
|
|
|
|
[ODBC Driver 18 for SQL Server]
|
|
|
|
|
Description=Microsoft ODBC Driver 18 for SQL Server
|
|
|
|
|
Driver=/opt/homebrew/lib/libmsodbcsql.18.dylib
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 二、在m1 mac下使用pymssql 连接sqlserver
|
|
|
|
|
参考官方文档 https://pymssql.readthedocs.io/en/stable/freetds.html
|
|
|
|
|
```shell
|
|
|
|
|
# 1.安装freetds
|
|
|
|
|
brew install freetds
|
|
|
|
|
# 2.修改配置
|
|
|
|
|
vim /opt/homebrew/etc/freetds.conf
|
|
|
|
|
在[global]下添加
|
|
|
|
|
port = 1443
|
|
|
|
|
tds version = 7.0
|
|
|
|
|
# 3.测试连接
|
|
|
|
|
tsql -H 172.16.1.2 -p 1433 -U sa -P atdPriME@Gy9# -D credit
|
|
|
|
|
# 返回以下情况说明连接成功
|
|
|
|
|
locale is "zh_CN.UTF-8"
|
|
|
|
|
locale charset is "UTF-8"
|
|
|
|
|
using default charset "UTF-8"
|
|
|
|
|
Setting credit as default database in login packet
|
|
|
|
|
```
|
|
|
|
|
freetds连接成功后安装pymssql
|
|
|
|
|
```shell
|
|
|
|
|
pip install pymssql
|
|
|
|
|
```
|