python连接数据库mysql
前提:电脑已经安装数据库环境
1、导入pymysql库
2、建立连接:
md = pymysql.connect(host='localhost',user='root',password='数据库密码',db='lili')
3、新建游标:
cur = md.cursor()
4、写sql
sql1 = """
create table grade(
name CHAR(20),
course CHAR(20),
goal CHAR(20)
"""
5、执行sql
cur.execute(sql1)
6、提交和关闭
md.commit()
cur.close()
md.close()
以上数据库中已经新建grade表
-------------------------------------------------------------------------------------

浙公网安备 33010602011771号