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()

 

posted on 2018-05-13 00:01  星河赵  阅读(217)  评论(0编辑  收藏  举报

导航