import mysql.connector
# Connect to the MySQL server
cnx = mysql.connector.connect(user='<username>', password='<password>',
host='<host>', database='<database>')
# Create a cursor object to execute the SQL queries
cursor = cnx.cursor()
# Execute the "SHOW DATABASES" query
cursor.execute("SHOW DATABASES")
# Fetch all the rows returned by the query
databases = cursor.fetchall()
# Print the names of the databases
for db in databases:
print(db[0])
# Close the cursor and connection
cursor.close()
cnx.close()