When using Azure Function to create a new Python Function,
ModuleNotFoundError: No module named'MySQLdb' appears when using MySQLdb to connect to the database,
But we can find this module by looking at the Python Site-Package in the Function App, but why is there still an error that the module cannot be loaded?
Check that the currently used Python version is 3.8, so go to the 3.8 version directory and find that there is no pymysql module.
Searching for the keywords of Python 3 and pymysql on the Internet, I found that Python 3 does not support the mysqlbd module. Instead, use the pymysql module.
pip install mysql-pythonto install and connect to the MySQL library, and import MySQLdb for use;
Using the pymysql module, and adding the content of
pymysql.install_as_MySQLdb() to the code, you can successfully access mysql.
import pymysql pymysql.install_as_MySQLdb()