import pymysql
# 打开数据库连接
db = pymysql.connect(host='47.104.*.*', #数据库服务器IP
port=3308,
user='root',
passwd='123456',
db='ernest' #数据库名称)

# 使用cursor()方法创建一个游标对象cur (可以理解为激活数据库)
cur = db.cursor()

# 使用execute()执行SQL语句
cur.execute("select * from student")

# 使用fetchall()方法获取查询结果 (接收全部的返回结果)
data = cur.fetchall()
print(data)

# 解决游标遍历慢的方法:一行一行去遍历,而不是一下全部读取出来
# for i in cur:
# print (i)
db.close()

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-11-03
  • 2021-11-19
  • 2021-10-01
  • 2021-09-29
  • 2021-09-29
猜你喜欢
  • 2021-09-18
  • 2021-11-14
  • 2021-11-21
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
相关资源
相似解决方案