我有Python 2.7版本,并下载了MySQL 8.0.13版本。当我尝试从链接安装正确的连接器并运行以下代码时:
当我使用pip安装SQL Connector并运行相同的代码时,会出现以下情况:
基于这篇文章,我猜可能是SQL连接器版本的问题。我搜索了一下,发现可以安装特定版本的SQL连接器,但我不知道需要哪个版本。
有人有想法吗?
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="Pass"
)
print(mydb)
模块未被识别:
Traceback (most recent call last):
File "C:\Users\carmel.han\Desktop\mysqltest.py", line 1, in <module>
import mysql.connector
ImportError: No module named mysql.connector
当我使用pip安装SQL Connector并运行相同的代码时,会出现以下情况:
Traceback (most recent call last):
File "C:\Users\carmel.han\Desktop\mysqltest.py", line 7, in <module>
auth_plugin='mysql_native_password'
File "C:\Python27\ArcGIS10.4\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Python27\ArcGIS10.4\lib\site-packages\mysql\connector\connection.py", line 95, in __init__
self.connect(**kwargs)
File "C:\Python27\ArcGIS10.4\lib\site-packages\mysql\connector\abstracts.py", line 719, in connect
self._open_connection()
File "C:\Python27\ArcGIS10.4\lib\site-packages\mysql\connector\connection.py", line 210, in _open_connection
self._ssl)
File "C:\Python27\ArcGIS10.4\lib\site-packages\mysql\connector\connection.py", line 144, in _do_auth
self._auth_switch_request(username, password)
File "C:\Python27\ArcGIS10.4\lib\site-packages\mysql\connector\connection.py", line 167, in _auth_switch_request
auth = get_auth_plugin(new_auth_plugin)(
File "C:\Python27\ArcGIS10.4\lib\site-packages\mysql\connector\authentication.py", line 191, in get_auth_plugin
"Authentication plugin '{0}' is not supported".format(plugin_name))
NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
我从pip 7.0.1升级到pip 18.1,卸载并重新安装了SQL-connector,但结果相同。即使我插入了这一行:
auth_plugin='mysql_native_password'
基于这篇文章,我猜可能是SQL连接器版本的问题。我搜索了一下,发现可以安装特定版本的SQL连接器,但我不知道需要哪个版本。
pip
默认安装了2.1.6
,我也尝试了2.1.4
,但没有成功。我使用的是Windows 10 64位操作系统。有人有想法吗?