<filename>create_table_mysql.py
import mysql.connector
from mysql.connector import Error
import time

try:
    connection = mysql.connector.connect(host='127.0.0.1',
                                        port=3308,
                                         database='freecode_students',
                                         user='root',
                                         password='')
    if connection.is_connected():
        db_Info = connection.get_server_info()
        print("Connected to MySQL Server version ", db_Info)
        cursor = connection.cursor()
        cursor.execute("select database();")
        record = cursor.fetchone()
        print("You're connected to database: ", record)
        mySql_Create_Table_Query = """CREATE TABLE IF NOT EXISTS Laptop ( 
                             Id int(11) NOT NULL,
                             Name varchar(250) NOT NULL,
                             Price float NOT NULL,
                             Purchase_date Date NOT NULL,
                             PRIMARY KEY (Id)) """
    cursor = connection.cursor()
    result = cursor.execute(mySql_Create_Table_Query)
    print("Laptop Table created successfully ")


except Error as e:
    print("Error while connecting to MySQL", e)
finally:
    if (connection.is_connected()):
        cursor.close()
        connection.close()
        print("MySQL connection is closed")
<filename>create_table_mysql.py
import mysql.connector
from mysql.connector import Error
import time

try:
    connection = mysql.connector.connect(host='127.0.0.1',
                                        port=3308,
                                         database='freecode_students',
                                         user='root',
                                         password='')
    if connection.is_connected():
        db_Info = connection.get_server_info()
        print("Connected to MySQL Server version ", db_Info)
        cursor = connection.cursor()
        cursor.execute("select database();")
        record = cursor.fetchone()
        print("You're connected to database: ", record)
        mySql_Create_Table_Query = """CREATE TABLE IF NOT EXISTS Laptop ( 
                             Id int(11) NOT NULL,
                             Name varchar(250) NOT NULL,
                             Price float NOT NULL,
                             Purchase_date Date NOT NULL,
                             PRIMARY KEY (Id)) """
    cursor = connection.cursor()
    result = cursor.execute(mySql_Create_Table_Query)
    print("Laptop Table created successfully ")


except Error as e:
    print("Error while connecting to MySQL", e)
finally:
    if (connection.is_connected()):
        cursor.close()
        connection.close()
        print("MySQL connection is closed")
CREATE TABLE IF NOT EXISTS Laptop (                               Id int(11) NOT NULL,                              Name varchar(250) NOT NULL,                              Price float NOT NULL,                              Purchase_date Date NOT NULL,                              PRIMARY KEY (Id))