python 链接mysql 修改查询删除语句
import mysql.connector.pooling config = {
"host": "localhost",
"port": 3306,
"user": "root",
"password": "",
"database": "demo"
} try:
pool = mysql.connector.pooling.MySQLConnectionPool(
**config,
pool_size=10
) con = pool.get_connection()
con.start_transaction()
cursor = con.cursor()
# 复制表结构
# sql= "create table t_emp_new like t_emp "
# cursor.execute(sql) sql = "select avg(sal) as avg from t_emp"
cursor.execute(sql)
# 取一条记录
temp = cursor.fetchone()
# 平均底薪
avg = temp[0] sql = " select deptno from t_emp group by deptno having avg(sal)> %s"
cursor.execute(sql,[avg])
# 取出所有记录
temp = cursor.fetchall()
# print(temp) # sql = "insert into t_emp_new select * from t_emp where deptno in ( "
# for index in range(len(temp)):
# one = temp[index][0]
# if index < len(temp) -1 :
# sql+= str(one)+ ","
# else:
# sql += str(one)
# sql += ")"
# # print(sql) insert into t_emp_new select * from t_emp where deptno in ( 10,20)
# cursor.execute(sql) # sql = "delete from t_emp where deptno in ("
# for index in range(len(temp)):
# one = temp[index][0]
# if index < len(temp)-1:
# sql += str(one)+ ","
# else:
# sql += str(one)
# sql += " )"
# # delete from t_emp where deptno in (10, 20)
# # print(sql)
# cursor.execute(sql) # 查询部门 编号
sql = " select deptno from t_dept where dname = %s"
cursor.execute(sql,['SALES'])
deptno = cursor.fetchone()
# print(deptno[0]) 30 sql = "update t_emp_new set deptno = %s"
cursor.execute(sql,[deptno[0]]) con.commit() except Exception as e:
print(e)
if 'con' in dir():
con.close()
python 链接mysql 修改查询删除语句的更多相关文章
- python链接mysql
1.安装MySQLdb MySQLdb 是用于Python链接Mysql数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MySQL C API 上建立的. 下载地址: ht ...
- python链接mysql pymysql
python链接mysql import pymysql conn = pymysql.connect(user=', database='gbt2019', charset='utf8') curs ...
- python 链接mysql 连接池
# python 链接mysqlimport mysql.connector.poolingconfig = { "host":"localhost", &qu ...
- python 链接mysql
下载对应版本 安装 https://dev.mysql.com/downloads/connector/python/ 创建链接 # python 链接mysqlimport mysql.conn ...
- python学习道路(day12note)(mysql操作,python链接mysql,redis)
1,针对mysql操作 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass'); 设置密码 update user set password ...
- Python --链接MYSQL数据库与简单操作 含SSH链接
项目是软硬件结合,在缺少设备的情况,需要通过接口来模拟实现与设备的交互,其中就需要通过从数据库读取商品的ID信息 出于安全考虑 现在很多数据库都不允许通过直接访问,大多数是通过SSH SSH : 数 ...
- 查找Mysql慢查询Sql语句
一.MySQL数据库有几个配置选项可以帮助我们及时捕获低效SQL语句 1,slow_query_log 这个参数设置为ON,可以捕获执行时间超过一定数值的SQL语句. 2,long_query_tim ...
- Python操作Mysql数据库时SQL语句的格式问题
一.概述 近日使用Python对Mysql数据库进行操作,遇到SQL语句死活出问题的情况.由于最初没有将异常打印出来,一直不知道原因.随后,将异常打印出来之后,通过异常信息,对代码进行修改.最终,成功 ...
- 工作随笔——mysql子查询删除原表数据
最近在开发的时候遇到一个mysql的子查询删除原表数据的问题.在网上也看了很多方法,基本也是然并卵(不是写的太乱就是效率太慢). 公司DBA给了一个很好的解决方案,让人耳目一新. DELETE fb. ...
随机推荐
- Cqoi2017试题泛做
Day1 4813: [Cqoi2017]小Q的棋盘 树形背包DP. #include <cstdio> #define maxn 110 #define R register #defi ...
- 计蒜客T2202 数三角形(提高组2017模拟赛(三)day2T3) LZOJ3878攻略
今天模拟赛考了一道计蒜客NOIP2017模拟赛(三)day2T3的数三角形,原题链接 https://nanti.jisuanke.com/t/T2202 ,LZOJ3878攻略.场上想了很久都没转化 ...
- Postman(二)、调试模式
postman提供了一个调试模式,很方便我们写脚本以及断言 在脚本中用console.log()打印,到控制台查看 比如写入如下脚本: 点击Send后,在控制台可以看到如下信息
- 通过Flink实现个推海量消息数据的实时统计
背景 消息报表主要用于统计消息任务的下发情况.比如,单条推送消息下发APP用户总量有多少,成功推送到手机的数量有多少,又有多少APP用户点击了弹窗通知并打开APP等.通过消息报表,我们可以很直观地看到 ...
- Wordpress可以用来做什么?
WordPress本身只是一款开源的.基于PHP的博客软件,但是由于WordPress的源码开源.结构优良.插件丰富.主题繁多,以至于是 WordPress成为世界上最流行的博客程序.<Word ...
- SpringBoot 使用定时任务动态执行任务
import com.patient.core.adapter.CorsFilter; import org.mybatis.spring.annotation.MapperScan; import ...
- ANR错误分析
链接1:https://www.cnblogs.com/xiyuan2016/p/6740623.html 链接2:https://www.jianshu.com/p/3959a601cea6
- FusionCharts的属性
FusionCharts 的 XML标签属性有一下四种数据类型 * Boolean - 布尔类型,只能为1或者0.例如:<graph showNames='1′ > * Number - ...
- 浏览器端-W3School-HTML:HTML DOM Style 对象
ylbtech-浏览器端-W3School-HTML:HTML DOM Style 对象 1.返回顶部 1. HTML DOM Style 对象 Style 对象 Style 对象代表一个单独的样式声 ...
- ListView 中图片错位的问题是如何产生的?
图片错位问题的本质源于我们的 listview 使用了缓存 convertView,假设一种场景,一个 listview 一屏显示九个item,那么在拉出第十个 item 的时候,事实上该 item ...