Python – MySQL Setup & Connectivity

In This Article or tutorial we will learn about, how to connect Python with MySQL database ( Python – MySQL Setup & Connectivity).

As you know to build real world applications or software, databases connectivity is compulsory. Python Programming language also support databases like MySQL, SQLite, MonogoDB, GadFly and Many others..

 

 MySQL installation

First of all you need to install MySQL in your system. You can download MySQL free from following link

https://dev.mysql.com/downloads/mysql/

 

Install MySQL Driver [MySQL Connector]

Python programming language must needs “MySQL Connector” driver to access or connect with database.

You can install “MySQL Connector” using PIP.   PIP already installed in Python environment.

To install “MySQL Connector”, open your command prompt, goto the location of PIP.

 

C:\Users\hp\AppData\Local\Programs\Python\Python36-32\Scripts>

 

And type the following command and press enter to install MySQL Driver

 

python -m pip install mysql-connector-python

 

Check the following screenshot to help

 

 

 

Create Python Connection with MySQL

To connect the Python with MySQL database you need username and password of your localhost. You set this username and password during installation of MySQL database. In my case username is “root” and password is “123456”.

Read : How to reset the MySQL root Password

Check the following example to understand

Example (Python – MySQL  Connectivity)

 

Output/Results

 

 

Get More Python Tutorials