Kendriya Vidyalaya Sangathan, Ahmedabad Region
Revision Worksheet
Interface Python with MySql
Subject: Computer Science
1 Identify the name of connector to establish bridge between Python and MySQL
a. [Link]
b. connector
c. [Link]
d. [Link]
2 Which function of connection is used to check whether connection to mysql is
successfullydone or not?
import [Link] as msq
con = [Link]( #Connection String ) # Assuming all parameter required
as passedif :
print(“Connected!”)
else:
print(“ Error! Not Connected”)
a. [Link]()
b. [Link]()
c. con.is_connected()
d. con.is_connect()
3 Identify the correct statement to create cursor:
import [Link] as msq
con = [Link]( #Connection String ) # Assuming all parameter required
as passedmycursor =
a. [Link]()
b. con.create_cursor()
c. con.open_cursor()
d. con.get_cursor()
4 What is the difference in fetchall() and fetchone()?
5 Which attribute of of cursor is used to get number of records stored in cursor
(Assumingcursor name is mycursor)?
a. [Link]
b. mycursor.row_count
c. [Link]
d. [Link]
6 The code given below reads the following record from the table named student and displays only
those records who have marks greater than 75:
RollNo – integer
Name – string
Class – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
• Username is root
• Password is tiger
• The table exists in a MYSQL database named school. Write the following missing statements to
complete the code: Statement 1 – to form the cursor object Statement 2 – to execute the query
that extracts records of those students whose marks are greater than 75. Statement 3- to read
the complete result of the query (records whose marks are greater than 75) into the object
named data, from the table student in the database.
7 Write all the steps for creating database connectivity?