Python 安装MSSQL驱动
时间: 2024-03-06 20:42:41 浏览: 92
python mysql 驱动安装包
以下是Python安装MSSQL驱动的步骤:
1.使用pip安装pyodbc库
```python
pip install pyodbc
```
2.下载并安装Microsoft ODBC Driver for SQL Server
下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=56567
3.安装完成后,使用以下代码测试连接:
```python
import pyodbc
server = 'your_server_name'
database = 'your_database_name'
username = 'your_username'
password = 'your_password'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
print("Connection successful!")
```
阅读全文