Install Mysqldb in Python

Install Mysqldb in Python

  1. Install the mysqldb Module With the mysqlclient Library in Python3
  2. Install the mysqldb Module With the pymysql Library in Python3

This tutorial will discuss the methods we can use to install the mysqldb module in Python3.

Install the mysqldb Module With the mysqlclient Library in Python3

The mysqldb module is no longer supported by Python 3.x. So, instead, we can install the mysqlclient library that does the same thing as the traditional mysqldb module.

The command to install the mysqlclient library is given below.

pip install mysqlclient

Once installed, we can now import our mysqlclient library and give it the alias mysqldb. This is demonstrated in this code snippet.

import mysqlclient as mysqldb

We can now use all the methods inside the mysqlclient library with the mysqldb.functionName() function call.

Install the mysqldb Module With the pymysql Library in Python3

We can also use the pymysql library rather than the mysqlclient library to replace our traditional mysqldb module. The command to install the pymysql library is given below.

pip install pymysql

Like the previous example, we can now import the pymysql library with the alias mysqldb in our code. The following code snippet demonstrates a working example of this phenomenon.

import pymysql as mysqldb

We can now call any method of the pymysql library with the mysqldb.functionName() function call.

Muhammad Maisam Abbas avatar Muhammad Maisam Abbas avatar

Maisam is a highly skilled and motivated Data Scientist. He has over 4 years of experience with Python programming language. He loves solving complex problems and sharing his results on the internet.

LinkedIn