Course Content

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

Course Content

Description

Fetch Data In Python From Mysql Database

 

In this lecture we will see that,

How to fetch, update, delete records from table ?

 

To update data :

import mysql.connector

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

query="update student set sname='Apple',semail='Apple@gmail.com' where sid=2"

cur=conn.cursor()

cur.execute(query)

conn.commit()

print('Data updated')

conn.close()

Output :

Data updated

 

To delete data :

import mysql.connector

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

query="delete from student where sid=1"

cur=conn.cursor()

cur.execute(query)

conn.commit()

print('Data deleted')

conn.close()

Output :

Data deleted

 

To print all the data to your console :

import mysql.connector

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

query="select*from student"

cur=conn.cursor()

cur.execute(query)

rows=cur.fetchall()

conn.commit()

conn.close()

print(rows)

for row in rows:

print(row)

 

  • All the data will be fetched down to the console.

 

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