KnowledgeBoat Logo
|

Computer Science

Write a Python code to insert a new record as per given table Student (No, Name, Age, Department, Fee, Sex) using MySQL connectivity.

Python

Python MySQL

2 Likes

Answer

import mysql.connector
mydb = mysql.connector.connect(host = "localhost", 
                                user = "root", 
                                passwd = "kboat123", 
                                database = "kboat_cbse_12")
mycursor = mydb.cursor()
mycursor.execute("INSERT INTO STUDENT VALUES(5, 'ANANYA', 23, 'COMPUTER', 450, 'F')")
mydb.commit()
print("Records added")
mydb.close()

Output

Records added

Answered By

2 Likes


Related Questions