属性错误:模块“mysql”没有“connector”属性

2024-10-01 15:30:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行macosmojave,试图通过spyderide(python3)使用MySQL python连接器连接到MySQL

但我得到了一个错误:

File "/Users/admin/Desktop/omgboi.py", line 5, in <module>
    mydb=mysql.connector.connect(host='localhost',user='root',passwd='hariom21feb',database='test')

AttributeError: module 'mysql' has no attribute 'connector'

我尝试通过bash安装和重新安装mysql连接器和mysql连接器python,但是没有成功。我也尝试过更改我的文件名,但没用。代码如下:

^{pr2}$

你知道我做错了什么吗?在


Tags: pyconnectoradmin错误linemysqluserspython3
1条回答
网友
1楼 · 发布于 2024-10-01 15:30:26

你是如何安装Connector/Python的?在

PyPI包mysql-connector已弃用,您应该使用正式的mysql-connector-python。在

最简单和推荐的方法是使用pip

pip install mysql-connector-python

有关此处安装的详细信息https://dev.mysql.com/doc/dev/connector-python/8.0/installation.html

相关问题 更多 >

    热门问题