1:Python安装pyodbc:pip install pyodbc
2:安装unixODBC-2.3.4.tar.gz
- ./configure
- make
- make install
3:下载基于python的MySQL驱动(mysql-connector-odbc-5.3.6-osx10.11-x86-64bit)
4:编写配置文件
vim /usr/local/etc/odbcinst.ini
[MySQL51]
Description=MySQL 5.1.8 driver for Unix
Driver=你的路径/mysql-connector-odbc-5.3.6-osx10.11-x86-64bit/lib/libmyodbc5a.so
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
5:使用pyodbc进行连接
import pyodbc
conn_info = (‘Driver{MySQL51};Server=%s;Port=%s;Database=%s;User=%s; Password=%s;Option=3;‘%(host, port, database, user,password))
mysql_conn = pyodbc.connect(conn_info)
mysql_cur = self.mysql_conn.cursor()
时间: 2024-10-29 12:29:21