Python 连接数据库 mysql

Posted 一天一点到

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()

 

以上是关于Python 连接数据库 mysql的主要内容,如果未能解决你的问题,请参考以下文章