pymsql基本用法
来源:互联网 发布:灵族捏脸数据 编辑:程序博客网 时间:2024/06/06 06:44
#!/usr/bin/env python# --coding = utf-8# Author Allen Leeimport pymysql#创建链接对象conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='root', db='test')#创建游标cursor = conn.cursor()#执行sql,更新单条数据,并返回受影响行数effect_row = cursor.execute("update hosts set host = 'abcd'")#插入多条,并返回受影响的函数effect_row = cursor.executemany("insert into hosts(host,color_id)values(%s,%s)",[("1.0.0.1",1,),("10.0.0.3",2)])#获取最新自增IDnew_id = cursor.lastrowid#查询数据cursor.execute("select * from hosts")#获取一行row_1 = cursor.fetchone()#获取多(3)行row_2 = cursor.fetchmany(3)#获取所有row_3 = cursor.fetchall()#重设游标类型为字典类型cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)#提交,保存新建或修改的数据conn.commit()#关闭游标cursor.close()#关闭连接conn.close()
阅读全文
0 0
- pymsql基本用法
- django + pymsql
- Python的数据库连接Pymsql
- 使用pymsql存取图片
- Django中使用pymsql
- python 使用pymsql连接数据库
- python---pymsql+flask_sqlalchemy连接数据库
- 基本用法
- 基本用法
- pip insatall pyMsql 安装成功,无法import
- pymsql 查询某一数据库的所有数据表
- 基本常用控件基本用法
- 基本常用控件基本用法
- gdb基本用法
- rpm的基本用法
- sfc的基本用法
- GDB基本用法zt
- GDB基本用法
- ibm 聊天机器人android 代码 readme
- [UILabel copyWithZone:]: unrecognized selector sent to instance
- Android解析和创建XML之学习笔记------SAX
- YARN的工作原理
- hibernate学习之实体类以及crud操
- pymsql基本用法
- 安卓设计模式之MVC
- adapter.notify()、notifyAll()、notifyDataSetChanged ()、notifyDataSetInvalidated ()的区别
- 将图片保存到本地相册
- Java_log2000_IO1
- logback 中文手册
- java poi实现数据库数据导出到excel
- http请求
- Java_log2000_IO2