0% found this document useful (0 votes)
4 views2 pages

Python PyMySQL Practicals

The document provides practical Python programs for interacting with a MySQL database using PyMySQL. It includes examples for connecting to the database, creating a table, inserting, updating, deleting, and displaying records. Each section includes code snippets and expected output for clarity.
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)
4 views2 pages

Python PyMySQL Practicals

The document provides practical Python programs for interacting with a MySQL database using PyMySQL. It includes examples for connecting to the database, creating a table, inserting, updating, deleting, and displaying records. Each section includes code snippets and expected output for clarity.
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

Class XII - Python MySQL (PyMySQL) Practical

Programs

1. Connect Python with MySQL


import pymysql
con = [Link](host="localhost", user="root", password="your_password", database="school")
print("Connection Successful!")
[Link]()

Output: Connection Successful!

2. Create Table
cur = [Link]()
[Link]("CREATE TABLE student (roll INT, name VARCHAR(30), marks INT)")
print("Table Created Successfully!")

Output: Table Created Successfully!

3. Insert Data
[Link]("INSERT INTO student VALUES (1, 'Rahul', 85)")
[Link]()
print("Record Inserted!")

Output: Record Inserted!

4. Display Records
[Link]("SELECT * FROM student")
rows = [Link]()
for r in rows:
print(r)

Output: (1, 'Rahul', 85)

5. Update Record
[Link]("UPDATE student SET marks=95 WHERE roll=1")
[Link]()
print("Record Updated!")

Output: Record Updated!

6. Delete Record
[Link]("DELETE FROM student WHERE roll=1")
[Link]()
print("Record Deleted!")

Output: Record Deleted!


7. Search Record
roll = int(input("Enter roll: "))
[Link]("SELECT * FROM student WHERE roll=%s", (roll,))
data = [Link]()
print(data)

Output: (2, 'Anita', 90)

You might also like