How to Check If a Database Exists By Accessing Database in Python


In this example we will show how to check if a database exists by accessing the database in Python.

Source Code

import mysql.connector

# connect to server
mydb = mysql.connector.connect(
    host="localhost",
    port=3306,
    user="yourusername",
    password="yourpassword",
    db="mydatabase"
)

# If the above code is executed with no error, the database "mydatabase" exists.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments