Open In App

How To Install Pymysql In Python?

Last Updated : 30 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

We want to connect our Python program to MySQL to execute our MySQL query to get some data from our MySQL database. We can achieve this easily by using the PyMySQL Python library. In this article, let us look at what PyMySQL is, its features, and how to install it using the pip package manager.

What is PyMySQL in Python?

The PyMySQL library in Python is one of the popular Python libraries. PyMySQL is a lightweight and pure Python-based MySQL client library. It allows your Python program to connect to the MySQL database and interact with it by executing the query from your Python program to manage your data. This library is typically useful when working on automation programs that involve MySQL databases for storing and retrieving data or even when working on data analysis tasks where your data is stored in a central store using MySQL, etc.

Features of PyMySQL in Python

  1. Pure Python Implementation: It is easy to install and doesn’t need any other external libraries or dependencies.
  2. Support for MySQL and MariaDB: PyMySQL library provides support for MySQL and MariaDB databases.
  3. Compatibility: It is compatible with the Python 3.x version. It can be viewed as a good alternative for MySQL-Python library as MySQL-Python library does not support Python 3.x version.

Why use PyMySQL?

PyMySQL library is a pure Python MySQL driver that is lightweight and easy to use, and that provides support for the Python 3.x version. It can be installed using the pip package manager and does not have any other external dependencies. Also, it is entirely open-source and hosted on Github, so you can peek into the source code of this library. It is released on PyPI.

Install PyMySQL in Python

You can use pip, which is a Python package manager, to install the pymysql library. In this article, we will cover the installation of the PyMySQL library in Windows as well as Linux:

  • Install PyMySQL on Windows
  • Install PyMySQL on Linux

Install PyMySQL on Windows

Below are some steps by which we can install PyMySQL in windows in Python:

Step 1: Open Command Prompt

Open Command Prompt on your Windows operating system.

Step 2: Install pymysql

Type the below command in the cmd you have opened:

pip install pymysql
pip-install-mysql

Install pymysql using pip.

If the above command throws an error, then type the below command:

python -m pip install pymysql
python--m-pip-install-mysql

Install pymysql using python pip

It will take a few seconds to install. Wait for some time for the installation to finish. Now, you have successfully installed pymysql on your Windows system.

Step 3: Verify Installation

You can verify whether the installation was successful, open a Python shell, and try importing the library. If the import statement runs without any error, it means your installation was successful.

verify

Verify pymysql installation

Install PyMySQL on Linux

Below are some steps by which we can install PyMySQL in linux in Python:

Step 1: Open Terminal

Open the Linux Terminal on your Linux machine.

Step 2: Install pymysql

Type the below command in the terminal you have opened:

pip3 install pymysql
pip3-install-pymysql

Install pymysql using pip3

If the above command doesn’t work, then run the below command:

python -m pip install pymysql
python--m-pip-install-pymysql

Install pymysql using python-pip

It will take a few seconds to install. Wait for some time for the installation to finish. Now, you have successfully installed pymysql on your Linux system.

Step 3: Verify Installation

You can verify whether the installation was successful, open a Python shell, and try importing the library. If the import statement runs without any error, it means your installation was successful.

Verify-Installation

Verify pymysql installation



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads