How to Install MySQLdb in Python
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
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]
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()