pymysqlpip install pymysql # 导入pymysql模块import pymysql # 连接databaseconn = pymysql.connect( host=“你的数据库地址”, user=“用户名”,password=“密码”, database=“数据库名”, charset=“utf8”) # 得到一个可以执行SQL语句的光标对象cursor = conn.cursor() # 执行完毕返回的结果集默认以元组显示# 得到一个可以执行SQL语句并且将结果作为字典返回的游标#cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 定义要执行的SQL语句sql = """CREATE TABLE USER1 (id INT auto_increment PRIMARY KEY ,name CHAR(10) NOT NULL UNIQUE,age TINYINT NOT NULL)ENGINE=innodb DEFAULT CHARSET=utf8; #注意:charset='utf8' 不能写成utf-8""" # 执行SQL语句cursor.execute(sql) # 关闭光标对象cursor.close() # 关闭数据库连接conn.close() bootstrap入门和flask_nav快速导航栏 转载自:https://www.cnblogs.com/wongbingming/p/6813221.html Author: Michelle19lLink: https://gitee.com/michelle19l/michelle19l/2020/04/24/Flask教程三/Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.Flask Donate微信支付寶Previous Postpython大作业报告Next PostFlask学习教程二——web表单详解 Recommend 2020-04-24Flask学习教程二——web表单详解 2020-04-22Flask学习教程一——基础