环境

ubuntu22,sqlserver2019,python3.10

工作需要连接sqlserver,本来在window开发环境就折腾够呛,又部署线上,当记录


步骤
  1. python连接sqlserver的库,一般就是pyodbc及pymssql库
pip install pyodbc
  • 1.

python连接sqlserver2019_sqlserver

  1. 安装ubuntu版本的odbc的依赖库
sudo apt-get install unixodbc
  • 1.

python连接sqlserver2019_python_02

  1. 依赖2
sudo apt-get install odbcinst
  • 1.

python连接sqlserver2019_python_03

  1. odbc驱动
# Debian/Ubuntu
sudo wget https://packages.microsoft.com/config/debian/11/prod.list
sudo mv ./prod.list /etc/apt/sources.list.d/mssql-release.list
wget https://packages.microsoft.com/keys/microsoft.asc
sudo apt-key add microsoft.asc
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql18
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

python连接sqlserver2019_sqlserver_04

大功告成,收工