1. 程式人生 > >Python MySQL - 建立/查詢/刪除資料庫

Python MySQL - 建立/查詢/刪除資料庫

#coding=utf-8
import mysql.connector
import importlib
import sys

#連線資料庫的資訊
mydb = mysql.connector.connect(
        host='115.xx.10.121',
        port='3306',
        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')