Create a Database in MySQL Using Python

In this tutorial, we will introduce the way to create a database in mysql using python.

1. Import library

import mysql.connector

2.Connect mysql server

db_connection = mysql.connector.connect(
  host="localhost",
  user="username_here",
  passwd="password_here",
)

3.Execute a sql to create database using python

my_database = db_connection.cursor()
sql = "CREATE DATABASE you_db_name"
my_database.execute(sql)