Python

Create a database in python

Pinterest LinkedIn Tumblr
## Connecting to the database

import mysql.connector as mysql

db = mysql.connect(
    host="localhost",
    user="root",
    passwd="root@123",
)

## 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")

Write A Comment