import the mysql
# install: mysql-connector-python first connect to the database and then open the cursor,
# create a new var for database and create a database and then execute it
import mysql.connector
conn = mysql.connector.connect(
host="localhost",
user="root",
password="",
)
# below code is to check
if conn.is_connected(): # to check whether database is connected or not
print("Connected to MySQL")
else:
print("Connection to MySQL failed")
cursorobj = conn.cursor()
if conn.is_connected():
try:
db="create database school"
cursorobj.execute(db)
print("database created")
except:
print("databse error....")
else:
print("Not connected to MySql, cannot create database ")
INT: integer 11 digit,
BIGINT: 20 digit,
TEXT:0- 6000 ,
VARCHAR:0 - 255,
LONGTEXT : more than 6000,
DATETIME: yyyy-mm-dd hh mm ss,
TIMESTAMP: current time,
TINYINT: 3 digit,
TIME: hh mm ss,