Pymysql实现往表中插入数据过程解析
作者:chuyaoxin 时间:2022-03-24 10:31:43
代码如下
# -*- coding = utf-8 -*-
# @time:2020/5/28/028 21:00
# Author:cyx
# @File:插入数据.py
# @Software:PyCharm
import pymysql
con = pymysql.connect(host='localhost',user='root',password='123456',database='python_db',port=3366)
# 创建游标对象
cur = con.cursor()
# 编写插入数据的sql
sql = 'insert into t_student(sname,age,score) values(%s,%s,%s)'
try:
# 执行sql
cur.executemany(sql,[('小楚',21,99.9),('小刘',20,59),('小朱',20,85),('小宋',22,95)])
# 提交事务
con.commit()
print('插入成功')
except Exception as e:
print(e)
con.rollback()
print('插入失败')
finally:
con.close()
结果
然后到Navicat for MySQL中验证
来源:https://www.cnblogs.com/cyx-b/p/12984010.html
标签:Py,mysql,表,插入,数据
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python通过队列实现进程间通信详情
2023-07-24 17:49:44
![](https://img.aspxhome.com/file/2023/9/68939_0s.png)
VScode查看python f.write()的文件乱码问题及解决方法
2023-01-25 19:02:10
![](https://img.aspxhome.com/file/2023/7/115007_0s.png)
Oracle学习笔记(六)
2012-01-05 18:55:27
详解Django中的权限和组以及消息
2022-08-03 16:13:14
python绘制漏斗图步骤详解
2021-06-17 22:57:57
![](https://img.aspxhome.com/file/2023/7/101247_0s.png)
Django实现跨域请求过程详解
2022-08-31 23:45:56
![](https://img.aspxhome.com/file/2023/6/101006_0s.png)
浅谈keras中的batch_dot,dot方法和TensorFlow的matmul
2023-04-08 07:21:28
![](https://img.aspxhome.com/file/2023/1/75951_0s.jpg)
离线安装Pyecharts的步骤以及依赖包流程
2021-12-16 11:43:12
![](https://img.aspxhome.com/file/2023/0/135170_0s.jpg)
ASP调用系统ping命令代码
2008-04-27 20:45:00
oracle的一些tips技巧
2009-03-02 11:06:00
多种网页弹出窗口代码
2007-11-24 21:13:00
利用ASP实现事务处理的方法
2010-05-11 16:53:00
python-opencv颜色提取分割方法
2022-01-22 06:26:23
![](https://img.aspxhome.com/file/2023/4/107624_0s.jpg)
python爬虫 urllib模块url编码处理详解
2021-09-13 02:24:37
python性能测量工具cProfile使用解析
2022-01-28 08:22:03
浅谈django框架集成swagger以及自定义参数问题
2022-01-09 20:25:10
![](https://img.aspxhome.com/file/2023/5/100795_0s.jpg)
Python 在 VSCode 中使用 IPython Kernel 的方法详解
2023-07-25 10:10:23
![](https://img.aspxhome.com/file/2023/7/72047_0s.png)
pygame实现贪吃蛇小游戏
2023-04-18 19:09:07
![](https://img.aspxhome.com/file/2023/2/105722_0s.jpg)
新手必备的Python实用技巧和工具
2022-08-20 04:59:01
浅谈Python中的可变对象和不可变对象
2021-07-17 16:58:49