0% found this document useful (0 votes)
3 views4 pages

MySQL Connectivity: Database Operations

The document contains four Python programs demonstrating MySQL connectivity using the mysql.connector library. The first program creates a database and a student table, inserts records, and retrieves them. The subsequent programs perform operations such as selecting, updating, deleting records, and fetching data in various ways from the student table.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

MySQL Connectivity: Database Operations

The document contains four Python programs demonstrating MySQL connectivity using the mysql.connector library. The first program creates a database and a student table, inserts records, and retrieves them. The subsequent programs perform operations such as selecting, updating, deleting records, and fetching data in various ways from the student table.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MySQL Connectivity – 1st program

import [Link] as sql

con=[Link](host='localhost',user='root',passwd='abcd1234')

cur=[Link]()

[Link]("create database IF NOT EXISTS school")

[Link]("SHOW DATABASES")

data=[Link]()

print(data)

[Link]("USE SCHOOL")

[Link]("CREATE TABLE IF NOT EXISTS STUDENT (ROLL INTEGER, NAME


VARCHAR(20), MARKS INTEGER)")

[Link]("SHOW TABLES")

data=[Link]()

print(data)

[Link]("Desc student")

data=[Link]()

print(data)

for i in range(5):

r=int(input("enter roll number"))

n=input("enter name")

m=int(input("enter marks"))

[Link]("INSERT INTO STUDENT VALUES({},'{}',{})".format(r,n,m))

[Link]()

[Link]("SELECT * FROM STUDENT")

data=[Link]()

for i in data:

print(i)

[Link]()
MySQL Connectivity – 2nd program

import [Link] as sql

con=[Link](host='localhost',user='root',passwd='abcd1234',database='school')

cur=[Link]()

[Link]("SELECT * FROM STUDENT WHERE MARKS <33")

data=[Link]()

for i in data:

print(i)

[Link]("UPDATE STUDENT SET MARKS=MARKS+5 WHERE MARKS BETWEEN 28


AND 32")

[Link]()

[Link]("SELECT * FROM STUDENT")

data=[Link]()

for i in data:

print(i)

[Link]()
MySQL Connectivity – 3rd program

import [Link] as sql

con=[Link](host='localhost',user='root',passwd='abcd1234',database='school')

cur=[Link]()

[Link]("SELECT * FROM STUDENT ")

data=[Link]()

for i in data:

print(i)

R=int(input("enter roll number whose record to be deleted"))

[Link]("DELETE FROM STUDENT WHERE roll={}".format(R))

[Link]()

[Link]("SELECT * FROM STUDENT")

data=[Link]()

for i in data:

print(i)

[Link]()
MySQL Connectivity – 4th program

import [Link] as sql

con=[Link](host='localhost',user='root',passwd='abcd1234',database='school')

cur=[Link]()

[Link]("SELECT * FROM STUDENT ")

data=[Link]()

print(data)

print("No. of records fetched :",[Link])

data=[Link](3)

for i in data:

print(i)

print("No. of records fetched :",[Link])

data=[Link]()

for i in data:

print(i)

print("No. of records fetched :",[Link])

[Link]()

You might also like