使用pymysql进行mysql数据库操作

在python中使用pymysql进行对mysql数据库的操作:

import pymysql

# 连接
con = pymysql.Connect(user='root', password='a123456', host='127.0.0.1', database='fans', port=3307)

# 游标 cursor
cursor = con.cursor()

# 查询 执行sql查询
author_sql = 'select * from fans_cmm_author limit 10'
cursor.execute(author_sql)

# 获取查询fetchone fetchall
# fetchone 获取一条
# result = cursor.fetchone()
# fetchall获取所有
result = cursor.fetchall()

for item in result:
    print(item)

# print(result)

  

 

posted on 2021-04-20 09:44  流星飞雨  阅读(42)  评论(0编辑  收藏  举报

导航