pymysql insert
2020-08-16 20:43
295 查看
pymysql insert
# 导入pymysql import pymysql # 建立连接 conn = pymysql.connect(host="localhost", user="root", password="root", database="books",port=3306,charset="utf8") # 获取游标 cursor = conn.cursor() # 执行SQL语句:执行插入语句 cursor.execute("insert into t_book(`id`,`title`,`pub_date`) values(4, '三体', '1970-01-01');") # 打印结果:由于执行的插入语句不会直接打印结果,所以需要再次执行一次查询,才能看到结果 cursor.execute("select * from t_book;") print(cursor.fetchall()) # 提交事务后才能在数据库中查看到结果,提交之前数据存在内存当中,提交之后数据存在硬盘当中 conn.commit() # 关闭游标 cursor.close() # 关闭连接 conn.close()
相关文章推荐
- 在python中使用pymysql往mysql数据库中插入(insert)数据实例
- pymysql 适配器操作mysql,语句困惑、字符类型困惑、 insert 完成后数据库仍为空
- python中使用pymysql往mysql数据库中插入(insert)数据
- SQLiteDatabase中query、insert、update、delete方法参数说明
- Python列表list内建函数用法实例分析【insert、remove、index、pop等】
- insert语句太长,有StringBuilder优化一下
- 35. Search Insert Position
- oracle中update,insert,delete的高级用法
- 使用PyMySQL操作mysql数据库
- android中SQLite数据库中用insert同时插入多条记录的方法和效率比较
- MySQL使用INSERT插入多条记录, 批量新增数据
- 在sqlServer中把数据导出为insert脚本
- php下 mysql实现拼接insert和update语句
- OCP-1Z0-051 第161题 insert子句中的子查询
- insertAdjacentHTML方法详解
- Insert Interval
- leetcode 35. Search Insert Position
- 带有OUTPUT的INSERT,DELETE,UPDATE
- LeetCode(35) Search Insert Position
- 【LeetCode】Search Insert Position