我正在努力;
我所做的是;
您知道如何为Python函数安装mysql模块并连接到数据库吗?
谢谢!
发布于 2017-11-20 07:25:48
根据您的描述,我认为您的问题是如何在Azure函数应用程序中安装Python第三方模块。
请参阅以下步骤:
步骤1:
登录库:https://Your_APP_NAME.scm.azurewebsites.net/DebugConsole。
在d:/home/site/wwwroot/<your function name>文件夹中运行下面的命令。(将花费一些时间)
python -m virtualenv myvenv步骤2:
通过以下命令在env/Scripts文件夹中加载env。
activate.bat步骤3:
您的shell现在应该以(env)作为前缀。
更新pip
python -m pip install -U pip安装您需要的
python -m pip install MySQLdb步骤4:
在您的代码中,更新sys.path以添加以下内容:
import sys, os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname( __file__ ), 'env/Lib/site-packages')))然后通过下面的代码片段连接到mysql db
#!/usr/bin/python
import MySQLdb
# Connect
db = MySQLdb.connect(host="localhost",
user="appuser",
passwd="",
db="onco")
cursor = db.cursor()
# Execute SQL select statement
cursor.execute("SELECT * FROM location")
# Commit your changes if writing
# In this case, we are only reading data
# db.commit()
# Get the number of rows in the resultset
numrows = cursor.rowcount
# Get and display one row at a time
for x in range(0, numrows):
row = cursor.fetchone()
print row[0], "-->", row[1]
# Close the connection
db.close()希望它能帮到你。
https://stackoverflow.com/questions/47360783
复制相似问题