10.python-5.3.2数据库的连接

10.python-5.3.2数据库的连接

10.python-5.3.2数据库的连接

10.python-5.3.2数据库的连接

import pymysql


connection = pymysql.connect(host = 'localhost', user = 'root', db = 'student', charset = 'utf8', passwd = 'as123=as123')

# 获取cursor,数据库执行对象
cursor = connection.cursor()

#定义sql
sql = 'select*from student'

#执行sql语句
students = cursor.execute(sql)

#通过fetchall获得所有的数据
result = cursor.fetchall()
print(result)
# 关闭链接
connection.close()

上一篇:C# 自定义鼠标样式


下一篇:redis由单机升级为集群