Python MySQL - 创建/查询/删除数据库

时间:2023-03-09 13:38:54
Python MySQL - 创建/查询/删除数据库
#coding=utf-8
import mysql.connector
import importlib
import sys #连接数据库的信息
mydb = mysql.connector.connect(
host='115.xx.10.121',
port='',
user='root',
password='xxxxxZ6XPXbvos', ) mycursor=mydb.cursor()
#创建数据库
mycursor.execute('create database test_cc')
#查询数据库
mycursor.execute('show databases')
for x in mycursor:
if 'test_cc' in x:
print '成功'
#删除数据库
mycursor.execute('drop database test_cc')