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.