之前试试用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'
找了十多分钟,,然后发现一个问题:
文件和模块重名了。。。(难怪自动联想也没弹出来,,,)
把文件名字改掉:
运行成功: