【发布时间】:2021-07-04 07:36:46
【问题描述】:
我一直在尝试连接 Python 和 MySql,但我不断收到错误消息。这是我的代码:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="kdvis",
password="root")
print (mydb)
这是我得到的错误:
Traceback (most recent call last):
File "C:\Users\kdvis\Desktop\flies\11\python\connection1.py", line 9, in <module>
mydb = mysql.connector.connect(
AttributeError: module 'mysql' has no attribute 'connector'
我重新配置了 MySql,收到了 caching_sha2_password 错误,sha256 密码需要 SSL 错误,user@localhost 错误的访问被拒绝,尝试在 MySql 上使用 alter 关键字更改我的 root 密码,并阅读了几乎所有解决方案,但没有奏效。
非常感谢您的帮助。
【问题讨论】:
-
尝试先更新它:'python -m pip install mysql-connector-python --upgrade' 你有python 2还是3?因为我用 Python 3 尝试过它并且它有效。
-
@Nexarius 表示已经满足要求。 (Python 3.8,我在标题中提到过)
-
@sahasrara62 谢谢,但没有,我已经访问了该页面 3 次