# -*- encoding: utf-8 -*- ''' @File : mysql_conn.py @License : (C)Copyright 2018-2022 @Modify Time @Author @Version @Desciption ------------ ------- -------- ----------- 2023/4/13 13:59 zart20 1.0 None ''' # pymysql 链接示例 import pymysql # db = pymysql.connect(host="127.0.0.1", port=3306, user='root', password="123123", charset="utf8") # 链接数据库管理系统 db = pymysql.connect(host="127.0.0.1", port=3306, user='root', password="123123", charset="utf8", database="student") # 链接数据库 cursor = db.cursor() # 实例化游标对象 cursor.execute("show databases;") # 显示所有数据库 cursor.execute("use student;") # 选择指定数据库 cursor.execute("show tables;") # 执行数据库查询 data = cursor.fetchall() # 取出游标中所有内容 print(data) cursor.close() c2 = db.cursor() # c2.execute("show databases;") c2.execute("show tables;") print(c2.fetchall()) # db.close() # 关闭数据库链接 # c3 = db.cursor() # c3.execute("show databases;") # print(c3.fetchall())