MySQL PYTHON Connectivity
MySQL PYTHON Connectivity
VIVA QUESTIONS
1. What is MySQL Connector/Python?
MySQL Connector/Python is a standardized database driver provided by MySQL. It is used to access the
MySQL database from Python.
2. What are the five major steps for connecting MySQL and Python?
There are five major steps for connecting MySQL and Python.
• Execute a query
Here, mysql.connector.connect is a MySQL-python library function that creates the connection and
returns a connection object, conn1. It connects to a specific MySQL database (test in this case) using the
given host (localhost in this case), username (root in this case) and password (tiger in this case).
cursor1 = conn1.cursor()
Here, cursor1 is a cursor object created using connection object conn1 using cursor() method.
Here, cursor1 is a cursor object which uses execute method to run the SQL query.
The sql query is given in the form of a string. The output of the SQL query is stored
The fetchnone() method returns a single record as a list/ tuple and None if no more
object.