![]() |
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
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 PythonYou 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 WindowsBelow 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
![]() Install pymysql using pip. If the above command throws an error, then type the below command: 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 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 pymysql installation Install PyMySQL on LinuxBelow 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
![]() Install pymysql using pip3 If the above command doesn’t work, then run the below command: 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 pymysql installation |
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |