【问题标题】:module 'mysql' has no attribute 'connector', trying to connect mysql to python (spyder 3.8)模块'mysql'没有属性'connector',试图将mysql连接到python(spyder 3.8)
【发布时间】: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 次

标签: python mysql-connector


【解决方案1】:

你是否从 pip 安装了 mysql。 如果从其他来源删除它并使用 coomand 从 pip 安装它。

pip install mysql

【讨论】:

  • 我有,谢谢。我认为应该是 pip install mysql-connector-python
猜你喜欢
  • 2018-06-16
  • 2018-03-12
  • 2021-08-12
  • 2014-07-26
  • 2019-10-16
  • 2021-04-29
  • 2015-07-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多