Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Insert Data Into a MySQL Database

 

In this video we will see that,

How we can insert data into a MySQL database ?

 

import mysql.connector

conn=mysql.connector.connect(host="localhost", database="School",user="root", password="root")

query="create table student(sid int primary key auto_incrememt,sname varchar(50),semail varchar(50))"

cur=conn.cursor()

cur.execute(query)

conn.commit()

print('Table created..!')

conn.close()

Output :

Table created..!

 

Now we will go into our database and see that is the table created or not. We'll see that the table which we coded is successfully created in database.

 

Now to insert values in the table from python, we'll do the following –

 

import mysql.connector

conn=mysql.connector.connect(host="localhost", database="School",user="root", password="root")

query="insert into student(sname,semail)values('John','john@gmail.com')"

cur=conn.cursor()

cur.execute(query)

conn.commit()

print('Data inserted')

conn.close()

Output :

Data inserted

 

Now when we go into mysql we will see that the data which we mentioned has been successfully inserted.

FAQs

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere