当前位置:首页 > Python教程 > python技巧

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‘)

 

原文:https://www.cnblogs.com/chengchengla1990/p/9957126.html


【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!