Attribute error:module #39;mysql#39; has no attribute #39;connector#39;(属性错误:模块#39;MySQL#39;没有属性#39;连接器#39;)
本文介绍了属性错误:模块';MySQL';没有属性';连接器';的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行MacOS Mojave,试图通过Spyder ide(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-Connector和MySQL-Connector-python,但不起作用。我还尝试更改了文件的名称,但效果不佳。代码如下:
import mysql.connector
import random
first_names=['Jodee,Marielle,Phillip,Colby,Stephany,Dione,Grover,Napoleon,Nicholas,Alysa,Noma,Leta,Ciera,Donny,Buc,Iren,Renato,Glory,Stacia,Bennie,Soo,Mitzie,Kaci,Peggy,Hilma,Melva,Cindie,Miyoko,Melina,Cammy,Blanche,Rhea,Jill,Kellye,Ailene,Vida,Alva,Sau,Hollis,Oswaldo,Marty']
last_names=['Bula,Bibi,Rolf,Tayna,Ardith,Art,Jeannetta,Patrina,Ronny,Maida,Cleopatra,Sherry,Vincenza,Sheri,Sherlyn,Shayne,Geneva,Javier,Celine,Saran,Shari,Boris,Gwyneth,Summer,Maryellen,Rufina,Essie,Palma,Rafael,Cordell,Jude,Jenine,Manuel,Cleveland,Daphine,Lavina,Candi,Rossie,Brunilda,Gilberte,Nick,Hoyt,Lucius,Ardis,Tyler,Dwain,Caleb,Aide,Mckinley,Margurite']
mydb=mysql.connector.connect(host='localhost',user='root',passwd='hariom21feb',database='test')
mycursor=mydb.cursor()
fkey=random.randint(0,49)
lkey=random.randint(0,49)
nkey=random.randint(0,50)
for i in range(nkey):
query=('insert into test value(%s,%s,%s,%s,%s)')
tup=('L5W4NW',first_names(fkey),last_names(lkey),'2970','completed')
mycursor.execute(query,tup)
mydb.commit()
知道我做错了什么吗?
推荐答案
您是如何安装的?
PyPI包mysql-connector
已弃用,应使用官方mysql-connector-python
。
最简单也是最推荐的方法是使用pip
:
pip install mysql-connector-python
有关安装的详细信息,请点击此处https://dev.mysql.com/doc/dev/connector-python/8.0/installation.html
这篇关于属性错误:模块';MySQL';没有属性';连接器';的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:属性错误:模块';MySQL';没有属性';连接器';


猜你喜欢
- MySQL(Windows10)使用 MyISAM 表进行 FULLTEXT 搜索不起作用 2022-01-01
- Oracle SQL 转置 2022-01-01
- MySql 错误 150 - 外键 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 在 Oracle 中创建 CTE 2022-01-01
- 创建索引时,具有 mysql 数据库迁移的实体框架失败 2022-01-01
- 如何在oracle中获取字符串最右边的10个位置 2021-01-01
- 如何将uuid存储为数字? 2021-01-01
- HEROKU - 无法运行 git push heroku master 2021-01-01
- SQL Server 将 Varchar 转换为日期时间 2021-01-01