Python Tutorial · Revision notes

Python MySQL

Python talks to MySQL through a connector library (mysql-connector-python or PyMySQL). You open a connection, get a cursor, run parameterised SQL, fetch rows, commit or roll back, and close resources.

Quick revision

  • pip install mysql-connector-python; keep credentials in environment variables.
  • connect() -> cursor() -> execute() -> fetch -> close in finally.
  • Always use %s placeholders; never string-format SQL.
  • INSERT/UPDATE/DELETE need commit(); errors need rollback().
  • LEFT JOIN keeps unmatched left rows; COUNT(col) ignores NULL.
  • Transactions are atomic: commit all or rollback all.
Read the full Python MySQL notes on Doubtclip →