Create a database in python

## Connecting to the database

import mysql.connector as mysql

db = mysql.connect(
    host="localhost",
    user="root",
    passwd="[email protected]",
)

## creating an instance of 'cursor' class which is used to execute the 'SQL' statements in 'Python'
cursor = db.cursor()

## creating a databse called 'realprogrammer'
cursor.execute("CREATE DATABASE realprogrammer")
Leave a Comment