1、问题:简单查询数据库用户表中的用户ID,用户表比较大,有一千多万条记录,用Mysql查询select uid as 用户ID from ucenter.usr_user 即可解决,但是用Python调用Pymysql链接数据库查询的时候非常慢,等了十分钟也没解决,但是加上限制查询条数select uid as 用户ID from ucenter.usr_user limit 100很快就能得到结果,具体原因是什么呢?
# 打开数据库连接(ip/数据库用户名/登录密码/数据库名)
db = pymysql.connect(host = "", user = "", passwd = "",\
db = "", port = )
#使用cursor()方法获取操作游标
cursor = db.cursor()
sql = '''
select uid as 用户ID
from ucenter.usr_user
'''
#使用execute方法执行SQL语句
cursor.execute(sql)
# 使用 fetchone() 方法获取一条数据
data=cursor.fetchall()
# 关闭数据库连接
db.close()