一个简单使用pymysql的例子(解决 module ‘pymysql‘ has no attribute ‘connect‘ 问题)

import pymysql

user= input('user>>: ').strip()
pwd = input('password>>: ').strip()
# 建立连接
conn=pymysql.connect(
    host='192.168.1.4', 
    port=3306,
    user='root',
    password='sa',
    db='pearadminflask',
    charset='utf8'
)

# 拿到游标
cursor=conn.cursor()

# 执行sql语句
sql = 'select * from userinfo where user = "%s" and pwd = "%s"'%(user,pwd)
rows = cursor.execute(sql)

cursor.close()
conn.close()

# 进行判断
if rows:
    print("登陆成功!")
else:
    print("登录失败!")

遇到问题:

AttributeError: partially initialized module ‘pymysql’ has no attribute ‘connect’ (most likely due to a circular import)

问题解决:
因为我把python文件命名为了 pymysql.py ,文件名与模块名重名,所以出错了。。。
一个简单使用pymysql的例子(解决 module ‘pymysql‘ has no attribute ‘connect‘ 问题)_第1张图片

一个简单使用pymysql的例子(解决 module ‘pymysql‘ has no attribute ‘connect‘ 问题)_第2张图片

你可能感兴趣的:(MySQL,sql,python,mysql)