This document provides information about using the MySQL Connector/Python to connect to and interact with MySQL databases from Python code. It discusses installing the MySQL Connector/Python driver, which allows Python programs to connect to MySQL servers and perform common SQL operations. It also presents an overview of different Connector/Python versions and the MySQL and Python versions they support.
1. Section: BS in Information Technology - 2A
Day: FRI
Time: 1:00-4:00
Instructor: Percival A. Fernandez, MSIT
2.
3. PYTHON + MYSQL
• This section shows you how to use MySQL Connector/Python to
access MySQL databases.
• You’ll learn how to connect to MySQL database and perform
common database operations such as SELECT, INSERT, UPDATE
and DELETE in Python
4.
5. GETTING STARTED WITH MYSQL PYTHON
CONNECTOR
• To access the MySQL database from Python, you need a
database driver. MySQL Connector/Python is a standardized
database driver provided by MySQL.
• MySQL Connector/Python is designed specifically to MySQL. It
supports all MySQL extensions such as LIMIT clause.
• MySQL Connector/Python allows you to compress the data
stream between Python and MySQL database server using
protocol compression. It supports connections using TCP/IP
socket and secure TCP/IP connection using SSL.
• MySQL Connector/Python is an API implemented using pure
Python. It means that you don’t need to install any MySQL client
library or any Python modules except the standard library.
6. GETTING STARTED WITH MYSQL PYTHON
CONNECTOR
• MySQL Connector/Python versions
• You will need to install the correct versions of Python, MySQL,
and Connect/Python. The following table illustrates the
compatible versions of Connect/Python, MySQL, and Python:
Connector/Pyth
on Version
MySQL Server Versions Supported Python
Versions
8.0 8.0, 5.7, 5.6, 5.5 3.6, 3.5, 3.4, 2.7
2.2 5.7, 5.6, 5.5 3.5, 3.4, 2.7
2.1 5.7, 5.6, 5.5 3.5, 3.4, 2.7, 2.6
2.0 5.7, 5.6, 5.5 3.5, 3.4, 2.7, 2.6
1.2 5.7, 5.6, 5.5 (5.1, 5.0,
4.1)
3.4, 3.3, 3.2, 3.1, 2.7, 2.6
7. INSTALLING MYSQL CONNECTOR/PYTHON
• Before installing MySQL Connector/Python, you need:
Root or Administrator privileges in order to perform the
installation.
Python installed on your system
Note that the MySQL Connector/Python installation requires
python to be in the system’s PATH or it will fail.
• The pip command allows you to install MySQL Python connector
on any Operating system including Windows, macOS, Linux,
and Unix:
9. INSTALLING MYSQL CONNECTOR/PYTHON
• Verifying MySQL Connector/Python installation
• After installing the MySQL Python connector, you need to
test it to make sure that it is working correctly and you are
able to connect to the MySQL database server without any
issues.
• To verify the installation, you use the following steps:
• Open Python command line
• Type the following code