Python操控Mysql数据库
本文最后更新于:1 年前
1. 首先导入所需要的包
import pymysql2. 链接mysql数据库服务
connc = pymysql.Connect(
# 默认只写用户名和密码以及数据库名称就足够了
user='root',
password="password",
database='mydatabase',
)3. 创建游标对象
cur = connc.cursor()4. 编写SQL语句
sql = 'select * from students'5. 使用游标对象去调用SQL
cur.execute(sql)6. 获取查询结果并打印
result = cur.fetchall()
print(result)7. 关闭游标和链接对象
cur.close()
connc.close()本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!