使用Python管理MySQL数据库,有录播直播私教课视频教程

查看所有数据库

from mysql.db_object import Database

db = Database(
    host="localhost",
    port=3306,
    database="",
    username="root",
    password="zhangdapeng520"
)
print(db.get_all_database())

删除数据库

from mysql.db_object import Database

db = Database(
    host="localhost",
    port=3306,
    database="",
    username="root",
    password="zhangdapeng520"
)
print(db.get_all_database())

db.delete_database("gx")
print(db.get_all_database())

添加数据库

from mysql.db_object import Database

db = Database(
    host="localhost",
    port=3306,
    database="",
    username="root",
    password="zhangdapeng520"
)
db.delete_database("gx")
print(db.get_all_database())

db.add_database("gx")
print(db.get_all_database())

重建数据库

from mysql.db_object import Database

db = Database(
    host="localhost",
    port=3306,
    database="",
    username="root",
    password="zhangdapeng520"
)
db.add_database_force("gx")
print(db.get_all_database())

判断数据库是否存在

from mysql.db_object import Database

db = Database(
    host="localhost",
    port=3306,
    database="",
    username="root",
    password="zhangdapeng520"
)
db.add_database_force("gx")
print("gx" in db.get_all_database())

你可能感兴趣的:(MySQL,python,数据库,python,oracle)