我们需要使用pyodbc从Python连接到MySQL。安装pyodbc后,这就是我们得到的:
pyodbc.connect("DRIVER={MySQL};SERVER=localhost;DATABASE=HAGC;USER=user;PASSWORD=pass;OPTION=3;") Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/usr/lib64/libmyodbc5.so' : file not found (0) (SQLDriverConnect)")
所以我尝试了两件事: 1-编辑/etc/odbcinst.ini。那没用。 2-创建指向/usr/lib64/libmyodbc5w.so的符号链接'/usr/lib64/libmyodbc5.so'
从Python测试:
pyodbc.connect("DRIVER={MySQL};SERVER=localhost;DATABASE=HAGC;USER=myuser;PASSWORD=mypassword")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('08S01', "[08S01] [unixODBC][MySQL][ODBC 5.3(w) Driver]Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (2002) (SQLDriverConnect)")
这是原始的/etc/odbcinst.ini:
[MySQL]
Description=ODBC for MySQL
Driver=/usr/lib/libmyodbc5.so
Setup=/usr/lib/libodbcmyS.so
Driver64=/usr/lib64/libmyodbc5.so
Setup64=/usr/lib64/libodbcmyS.so
FileUsage=1
[MySQL ODBC 5.3 Unicode Driver]
Driver=/usr/lib64/libmyodbc5w.so
UsageCount=1
[MySQL ODBC 5.3 ANSI Driver]
Driver=/usr/lib64/libmyodbc5a.so
UsageCount=1