MySQL is a Relational Database Management System (RDBMS) whereas the structured Query Language (SQL) is the language used for handling the RDBMS using commands i.e Creating, Inserting, Updating and Deleting the data from the databases. SQL commands are case insensitive i.e CREATE and create signify the same command.
In this article, we will be discussing the MySQL Connector module of Python, how to install this module and a piece of code on how to connect this with the MySQL database. For any application, it is very important to store the database on a server for easy data access.
What is MYSQL Connector/Python?
MySQL Connector/Python enables Python programs to access MySQL databases, using an API that is compliant with the Python Database API Specification v2.0 (PEP 249). It is written in pure Python and does not have any dependencies except for the Python Standard Library.
There are various versions of MySQL Connector/Python available:
|Connector/Python Version||MySQL Server Versions||Python Versions|
|8.0||8.0, 5.7, 5.6, 5.5||3.8, 3.7, 3.6, 3.5, 3.4, 2.7|
|2.2 (continues as 8.0)||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|
This module does not come built-in with Python. To install it type the below command in the terminal.
pip install mysql-connector-python
If any issue is there while installing, one can explicitly specify the module version as follows:
pip install mysql-connector-python==8.0.17
Also, to uninstall current MySQL Connector/Python, you use the following command:
pip uninstall mysql-connector-python
Verifying MySQL Connector/Python installation
After installing the MySQL Python connector, we need to test it to make sure that it is working correctly and we are able to connect to the MySQL database server without any issues.
To verify the installation, we can use the following steps:
- Open Python command line
- Type the following code
If you see the following output, it means that you have been successfully installing the MySQL Connector/Python on your system.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.