Summary Table: MySQL and Python Connectivity Methods
Method / Attribute Belongs To Purpose
connect() [Link] Establishes connection to
MySQL database
cursor() Connection object Creates a cursor for
executing SQL queries
execute() Cursor Executes SQL query
(SELECT, INSERT, UPDATE,
DELETE)
fetchone() Cursor Fetches the next single
record from result set
fetchall() Cursor Fetches all remaining
records from result set
fetchmany(n) Cursor Fetches n number of
records from result set
commit() Connection Saves changes (commits
transactions)
rollback() Connection Cancels uncommitted
changes
rowcount Cursor Returns number of rows
affected by last SQL
command
close() Connection/Cursor Closes the cursor or
connection properly