之前试试用python 连接 mysql ,用到了pymysql模块,程序如下:

import pymysql

connection = pymysql.connect('localhost', 'root', '123456', 'python_opmysql')


sql = "create table wee (name varchar(10), age int(2));"

cursor = connection.cursor()

cursor.execute(sql)

connection.commit()
connection.close()

然后报错了:

AttributeError: module 'pymysql' has no attribute 'connect' 

找了十多分钟,,然后发现一个问题:

pymysql 报错:module 'pymysql' has no attribute 'connect'

文件和模块重名了。。。(难怪自动联想也没弹出来,,,)

pymysql 报错:module 'pymysql' has no attribute 'connect'

把文件名字改掉: 

pymysql 报错:module 'pymysql' has no attribute 'connect'

运行成功:
pymysql 报错:module 'pymysql' has no attribute 'connect'

 

相关文章:

  • 2021-09-02
  • 2021-09-15
  • 2021-11-25
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-04-07
猜你喜欢
  • 2021-08-02
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-01-07
相关资源
相似解决方案