Python 连接数据库 mysql

python 连接 数据库

import pymysql
db = pymysql.connect(host='127.0.0.1',port=3306,user='root',password='root',db='odps_test', charset="utf8")
# # 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()


#创建student表
Student = '''
    create table Student(
        StdID int primary key not null,
        StdName varchar(100) not null,
        Gender enum('M','F') not null,
        Age int 
    )
'''
cursor.execute(Student)
#关闭数据库连接
db.close()

猜你喜欢

转载自www.cnblogs.com/zhaoyingjie/p/9030660.html