sscasc@tumkur connect(function establishes connection to the mysql database from python application and returns mysqlconnection object this process automates logging into the database and selecting database to be used then we can use mysqlconnection object to perform various operation on the mysql database connect (function can throw an exceptioni database error if one of the required parameters are wrong for exampleif you provide database name that is not present in mysqlthen python application throws an exception so check the arguments that you are passing to this function the syntax for calling the connect(function and assigning the results to variable is as follows[variablemysqldb connect([hostname][username][password][database name]we can assign values these variables as shown but it is not requiredbut it is good practice until you get used to the format of the function call so we can use the following format to call the connect(function[variablemysqldb connect(host="[hostname]"user="[username]"passwd="[password]"db="[database name]"or (in case of mysql db[variablemysql connector connect (host="[hostname]"user="[username]"passwd="[password]"db="[database name]"conn is_connected(is_connected(is the function of the mysqlconnection class through which we can verify is our python application connected to mysql creating cursor objectusing cursor objectwe can execute sql queries the mysql cursor class instantiates objects that can execute operations such as sql statements cursor objects interact with the mysql server using mysqlconnection object after the connection object is createdcursor object allows to interact with the database the point of cursor is to mark place and to allows to issue commands to the computer cursor in mysql for python serves as python-based proxy for the cursor in mysql shell sessionwhere mysql would create the real cursor for us if we logged into mysql database to create the cursorwe use the cursormethod of the mysqldb connections object we created for the connection the syntax is as follows[cursor name[connection object namecursor(examplecursor mydb cursor(cursor close(using cursor' close method we can close the cursor object once we close the cursor objectwe can not execute any sql statement connection close(at lastwe are closing the mysql database connection using close(function of mysqlconnection class sp_python programming