我已经安装了 MySQL 连接器/Python 模块。它显示在目录 /usr/lib/python2.7/site-packages/mysql/connector/ 中。我还将此目录添加到 $PATH。
当我执行以下 Python 程序时,出现以下错误。
import mysql.connector
config = {
"database": "XXXX",
"host": "XXXX",
'user': 'XXXX',
"password": "XXXX",
"table": "XXXX",
"charset": "utf8"
}
try:
cnx = mysql.connector.connect(**config)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exists")
else:
print(err)
else:
cnx.close()
错误:
Traceback (most recent call last):
File "config.py", line 1, in <module>
import mysql.connector
File "/usr/lib/python2.7/site-packages/mysql/connector/__init__.py", line 28, in <module>
File "/usr/lib/python2.7/site-packages/mysql/connector/connection.py", line 39, in <module>
File "/usr/lib/python2.7/site-packages/mysql/connector/protocol.py", line 34, in <module>
ImportError: No module named authentication
在/usr/lib/python2.7/site-packages/mysql/connector/目录下,有authentication.py和authentication.pyc。
我不明白这个问题...