【insert】

 import MySQLdb

 conn = MySQLdb.connect("192.168.100.150","u01","","08day5" )
cur = conn.cursor() #把数据放到元组
sql = "insert into wang (id,name) values(%s,%s)"
params = (3,'wangsuchen') cur.execute(sql,params)
conn.commit() #提交 cur.execute('select * from wang')
print cur.fetchall() #必须在上一条execute命令执行后再执行这条, cur.close()
conn.close()

【delete】

 import MySQLdb

 conn = MySQLdb.connect("192.168.100.150","u01","","08day5" )
cur = conn.cursor() sql = "delete from wang where id = %s"
params = (3) cur.execute(sql,params)
conn.commit() cur.execute('select * from wang')
print cur.fetchall() cur.close()
conn.close()

【updata】

import MySQLdb

conn = MySQLdb.connect("192.168.100.150","u01","","08day5" )
cur = conn.cursor() sql = "update wang set name = %s where id = %s"
params = ('chenying',2) cur.execute(sql,params)
conn.commit() cur.execute('select * from wang')
print cur.fetchall() cur.close()
conn.close()

【select】

 import MySQLdb

 conn = MySQLdb.connect("192.168.100.150","u01","","08day5" )
cur = conn.cursor() cur.execute('select * from wang')
print cur.fetchall() cur.close()
conn.close()

python操作mysql之增删改查的更多相关文章

  1. python操作mysql数据库增删改查的dbutils实例

    python操作mysql数据库增删改查的dbutils实例 # 数据库配置文件 # cat gconf.py #encoding=utf-8 import json # json里面的字典不能用单引 ...

  2. Asp.Net操作MySql数据库增删改查

    Asp.Net操作MySql数据库增删改查,话不多说直接步入正题.git源码地址:https://git.oschina.net/gxiaopan/NetMySql.git  1.安装MySQL数据库 ...

  3. python2.7入门---操作mysql数据库增删改查

    Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口.Python 数据库接口支持非常多的数据库,你可以选择适合你项目的数据库: G ...

  4. Python实现mysql数据库增删改查

    利用python操作mysql数据库用法简单,环境配置容易,本文将实现对库增.删.改.查的简易封装!   1. 环境配置 安装第三方包  ,导入模块 mysql.connector  pip inst ...

  5. Golang原生sql操作Mysql数据库增删改查

    Golang要操作mysql数据库,首先需要在当期系统配置GOPATH,因为需要使用go get命令把驱动包下载到GOPATH下使用. 首先配置好你的GOPATH,执行以下命令,下载安装mysql驱动 ...

  6. shell操作mysql之增删改查

    假设mysql用户名root 密码123456,新建测试数据表utable 脚本如下: #!/bin/bash#mysqlop.shmysql="/app/local/mysql/bin/m ...

  7. java操作mysql的增删改查

    prepareStatement(sql)是statement的子类,比statement好用. 如果数据库中定义的是int值,那么sql语句中要把int单独提出来.如".....value ...

  8. python3操作mysql数据库增删改查

    #!/usr/bin/python3 import pymysql import types db=pymysql.connect("localhost","root&q ...

  9. python操作三大主流数据库(8)python操作mongodb数据库②python使用pymongo操作mongodb的增删改查

    python操作mongodb数据库②python使用pymongo操作mongodb的增删改查 文档http://api.mongodb.com/python/current/api/index.h ...

随机推荐

  1. js如何获取到select的option值???

    1.获得选项option的值 var obj = document.getElementByIdx_x(”testSelect”); //定位id var index = obj.selectedIn ...

  2. 如何在CentOS 7上安装newman

    前提:先安装nodejs,详见:如何在CentOS 7上安装Node.js和npm #sudo npm install -g newman 结果: /usr/local/bin/newman -> ...

  3. 原生JS代码实现随机产生一个16进制的颜色值

    封装一个函数 function getColor() { var str = "#"; //一个十六进制的值的数组 var arr = ["0", " ...

  4. 行人重识别(ReID) ——技术实现及应用场景

    导读 跨镜追踪(Person Re-Identification,简称 ReID)技术是现在计算机视觉研究的热门方向,主要解决跨摄像头跨场景下行人的识别与检索.该技术能够根据行人的穿着.体态.发型等信 ...

  5. 【转】 linux硬链接与软链接

    转自:http://www.cnblogs.com/yfanqiu/archive/2012/06/11/2545556.html Linux 系统中有软链接和硬链接两种特殊的“文件”. 软链接可以看 ...

  6. scapy - 基于python的数据包操作库

    简介 地址:https://github.com/secdev/scapy scapy是一个基于python的交互式数据包操作程序和库. 它能够伪造或者解码多种协议的数据包,通过使用pcap文件对他们 ...

  7. Java垃圾回收【GC】机制详解

    一.为什么需要垃圾回收 如果不进行垃圾回收,内存迟早都会被消耗空,因为我们在不断的分配内存空间而不进行回收.除非内存无限大,我们可以任性的分配而不回收,但是事实并非如此.所以,垃圾回收是必须的. 二. ...

  8. 【串线篇】spring boot页面模板引擎

    如JSP.Velocity.Freemarker.Thymeleaf SpringBoot推荐的Thymeleaf:语法更简单,功能更强大: 一.引入thymeleaf <dependency& ...

  9. Redis-缓存击穿/穿透/雪崩

    缓存击穿/穿透/雪崩 Intro 使用缓存需要了解几个缓存问题,缓存击穿.缓存穿透以及缓存雪崩,需要了解它们产生的原因以及怎么避免,尤其是当你打算设计自己的缓存框架的时候需要考虑如何处理这些问题. 缓 ...

  10. H700关闭Direct PD Mapping

    Attached Enclosure doesn't support in controller's Direct mapping modePlease contact your system sup ...