Python MySQL

In database applications, Python may be utilised.

MySQL is one of the most famous databases.

You can also search for these topics, python mysql access, best practices for mysql in python, example for python mysql, python delete and documentation with mysql, check the working of python mysql function, python mysql in python interface, check the python mysql working, python mysql primary key and key value.

MySQL Database

You should have installed MySQL on your computer in order to be able to explore with code samples in this tutorial.

The free MySQL database can be downloaded from

You can also search for these topics, python mysql database access, connection of python database with mysql, example for mysql database in python, python and mysql database a practical introduction, create the database mysql using python, how to use the python mysql database, how to update the python mysql database, list out the database in python mysql.

Install MySQL Driver

For access to the MySQL database, Python needs a MySQL driver.

We suggest that you install MySQL Connector driver using PIP.

Type the following command in command-prompt to download and install the MySQL Connector using PIP location.

E:\>python -m pip install mysql-connector-python

Now you have a MySQL driver downloaded and installed.

You can also search for these topics, python install mysql driver connector, how to install the python mysql driver best practices, how to python install mysql driver for python, pip to install in python mysql driver, how to locate the python driver mysql.

Test MySQL Connector

If you have already installed a "MySQL Connector", create a python file with the following text to test if it was successful :

import mysql.connector


#if this file is executed with no errors, you have the "mysql.connector" module installed.

Output :-


If there are no mistakes in the above code, "MySQL Connector" is installed and ready to use.

You can also search for these topics, python unit test mysql connector, Test the mysql connector version in python, python test mysql connector alternative, connector to delete the connector in mysql example, how python errror handling works in mysql connector, empty the mysql connector result using python.

Create Connection

Begin by building a database connection.

Use your MySQL database username and password.

import mysql.connector

mydb = mysql.connector.connect(


Output :-

<mysql.connector.connection.MySQLConnection object ar 0x016645F0>

Use SQL command to start the database query now.

You can also search for these topics, python create connection example, working of python function to create connection, python create connection file, check the create connection interface with python, python to create new folder connection, process the connection to create using python, python project and package to create connection.