import MySQLdb # 创建一个数据库连接对象 conn = MySQLdb.connect( host='localhost', port=3306, user='root', password='123456' ) # 获取连接的游标 cursor = conn.cursor() # 执行语句,创建数据库TestDB cursor.execute('create database TestDB') cursor.execute('drop database TestDB') # 执行语句,展示所有数据库 cursor.execute('show databases') # 遍历所有数据库 (多维元组) for i in cursor: print(i) # 关闭游标 cursor.close() # 关闭连接 conn.close()
标签:execute,删除,python,创建,数据库,cursor,TestDB,conn From: https://www.cnblogs.com/wusen0601/p/16722616.html