How to Install MySQLdb in Python
![how to install mysqldb in python](https://pythonpoint.net/wp-content/uploads/2020/12/how-to-install-mysqldb-in-python-1024x576.jpg)
MySQLdb is an interface for connecting to a MySQL database server from Python. But there are some complications with the installation of MySQLdb in Windows.
The installation of MySQLdb using the pip command pip install MySQL-python
may cause some issues. In this article, we will show you a hasslefree method for installing MySQLdb.
Installing MySQLdb on Windows
To install MySQLdb on Windows, go to this link – https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-2020-12-09-103218.jpg)
Download the appropriate .whl for your Python version.
I am using Python 3.8, so I downloaded mysqlclient‑1.4.6‑cp38‑cp38‑win_amd64.whl
.
In windows command prompt, install the .whl file using pip. Remember to provide correct directory where the downloaded .whl file resides.
pip install [.whl filename]
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-2020-12-09-103727-1024x263.jpg)
Your MySQLdb installation is complete. If you want to test the installation, run the following code by providing valid informations.
import MySQLdb print("Connecting to database using MySQLdb") db_connection = MySQLdb.connect(host='DB_HOST', db='DB_NAME', user='DB_USERNAME', passwd='DB_PASSWORD') print("Succesfully Connected to database using MySQLdb!") db_connection.close()