码迷,mamicode.com
首页 > 数据库 > 详细

Python 连接数据库 mysql

时间:2018-05-13 00:38:39      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:var   import   关闭数据库   创建   end   方法   使用   not   nec   

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

标签:var   import   关闭数据库   创建   end   方法   使用   not   nec   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!