pysql模块的练习

  • 连接数据库
  • 创建游标对象
  • 创建表
    上代码:
# -*- coding:utf-8 -*-  
import pymysql
# 创建连接
con=pymysql.connect(host='localhost',user='root',password='123456',database='ges_data',port=3306)
# 创建游标对象
cur=con.cursor()
# 创建表的sql语句
sql='''
    create table T_student
    (
    sno int primary key auto_increment,
    sanme varchar(30) not null,
    age int(2),
    score float(3,1)
    )
'''
try:
    cur.execute(sql)
    print('创建表成功')    
except Exception as e:
    print(e)
    print('创建失败')  
finally:
    con.close()
    print('关闭连接')

发布了15 篇原创文章 · 获赞 12 · 访问量 222

猜你喜欢

转载自blog.csdn.net/weixin_45116096/article/details/105469964
今日推荐