flask数据库
# 框架环境 安装 Flask_SQLALchemy,mysqlclient from flask import Flask from flask_sqlalchemy import SQLALchemy # 导入数据库模块 app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = 'mysql://root:123456@127.0.0.1/mysql' # 连接数据库 用户名 密码 host 数据库:mysql db = SQLALchemy(app) # 实例化数据库 @app.route('/') def index(): from sqlalchemy import text slq = text("SELECT * FROM 'USER' ") # sql 语句 result = db.engine.execute(sql) # 执行sql语句 查询 for row in result: app.logger.info(row) # 日志打印出查询结果 return "数据库测试" if __name__ == "__main__": app.run(host="0.0.0.0",debug=Ture)