数据库 mysql 和 pycharm交互

# #导入pymysql模块
# import pymysql
#
# #建立和数据库的连接
# # 参数1:数据库的ip(localhost为本地ip的意思)
# # 参数2:数据库端口
# # 参数3,4:用户及密码
# # 参数5:数据库名
# con=pymysql.connect(host='localhost',port=3306,database='test',user='root',password='')
# print(con)
#
# #建立游标
# cur=con.cursor()
# #用游标去执行sql语句
# r=cur.execute('insert into t2 values (1)')
#
# #execute方法执行sql语句,返回值是影响了多少行
# print(r)
#
# # 用连接提交
# con.commit()
#
# # 关闭连接
# con.close()






# import pymysql
#
# # MySQL中库和表已经建完了
#
# # 建立连接
# # con=pymysql.connect(host='127.0.0.1'数据库的ip,port=默认端口,user='root'用户,,passwd=''密码,db='库名')
# con=pymysql.connect(host='localhost',port=3306,user='root',passwd='',db='test')
# print(con)
#
# # 建立游标
# cur=con.cursor()
#
# # # 用游标执行sql
# # # 增
# # # a=cur.execute('insert into 表 values()')
# # a=cur.execute('insert into py1 values(7,8)')
# #
# # # 删
# # # b=cur.execute('alter table py1 drop a')
# # c=cur.execute('delete from py1 where a=1')
# # # 改
# # d=cur.execute('update py1 set b=1 where a=7')
# # # 查
# # e=cur.execute('update py1 set b=1 where a=7')
# #
# r=cur.execute('select * from py1')
#
# # 将结果集数据分离出来
# # result=cur.fetchall()
# # cur 在查找的sql语句之后,就变成了结果集
# # 需要从结果集中分理处数据
#
# # 逐条分离结果集数据
# result1=cur.fetchone()
#
# # 制定数量分离结果集数据
# # result2=cur.fetchmany(2)
#
# # print(result)
# print(result1)
# # print(result2)
#
# # 提交
# con.commit()
# # print(a)
#
# # 关闭连接
# con.close()
posted on 2019-05-30 20:47 女己。 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/wyf2019/p/10951956.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值