首页 > 数据库技术 > 详细

Python 连接数据库 mysql

时间:2018-05-13 00:15:50      阅读:233      评论:0      收藏:0      [点我收藏+]

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

 

Python 连接数据库 mysql

原文:https://www.cnblogs.com/zhaoyingjie/p/9030660.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!