python开发过程中用到数据库无外乎MYSQL,Mangodb,redis三种,三者数据库使用可能存在差异,但在一些基础的语句使用时都是大同小异的,这阶段学习了一些基础操作,记录下

add:

# -*- coding: utf-8 -*-
import MySQLdb
try:
conn=MySQLdb.connect(host='192.168.65.146',port=3306,db='student',user='root',passwd='toor',charset='utf8')
csl=conn.cursor()
count=csl.execute("insert into stu(stu_id,stu_name,stu_phone,stu_hometown) values('0003','kj','19564832601',河北)")
print(count)
conn.commit()
csl.close()
conn.close()
except Exception as e:
print (e).

delete:

# -*- coding:utf-8 -*-
import MySQLdb
try:
conn=MySQLdb.connect(host='192.168.65.146',port=3306,db='student',user='root',passwd='toor',charset='utf8')
cs1=conn.cursor()
count=cs1.execute("delete from stu where stu_id=4")
print(count)
conn.commit()
conn.close()
except Exception as e:
print(e)

update:

# -*- coding:utf-8 -*-
import MySQLdb
try:
conn=MySQLdb.connect(host='192.168.65.146',port=3306,db='student',user='root',passwd='toor',charset='utf8')
cs1=conn.cursor()
count=cs1.execute("update stu set stu_phone='10005954565' where stu_name='张良'")
print(count)
conn.commit()
conn.close()
except Exception as e:
print(e)

search:

# -*- coding: utf-8 -*-
import MySQLdb
try:
conn=MySQLdb.connect(host='192.168.65.146',port=3306,db='student',user='root',passwd='toor',charset='utf8')
cs1=conn.cursor()
#cs1.execute("select * from stu where stu_id=1")
#result=cs1.fetchone() 查询一行
cs1.execute("select * from stu")
result=cs1.fetchall()#查询全部
print(result)
cs1.close()
conn.close()
except Exception as e:
print(e)

python & MySQLdb(one)的更多相关文章

  1. Python爬虫(一)

    花了四天的时间用python写了个简单的爬虫程序.整个过程分为两个部分:工具的安装和程序的实现 本文并没有讲程序的详细实现遇到的问题,而是对着手前一些前期的准备 第一部分(工具的安装) 开发工具的下载 ...

  2. python自动化测试(2)-自动化基本技术原理

    python自动化测试(2) 自动化基本技术原理 1   概述 在之前的文章里面提到过:做自动化的首要本领就是要会 透过现象看本质 ,落实到实际的IT工作中就是 透过界面看数据. 掌握上面的这样的本领 ...

  3. Python小白的发展之路之Python基础(一)

    Python基础部分1: 1.Python简介 2.Python 2 or 3,两者的主要区别 3.Python解释器 4.安装Python 5.第一个Python程序 Hello World 6.P ...

  4. python自动化测试(4)-使用第三方python库技术实现

    python自动化测试(4)-使用第三方python库技术实现 1   概述 关于测试的方法论,都是建立在之前的文章里面提到的观点: 功能测试不建议做自动化 接口测试性价比最高 接口测试可以做自动化 ...

  5. python自动化测试(3)- 自动化框架及工具

    python自动化测试(3) 自动化框架及工具 1   概述 手续的关于测试的方法论,都是建立在之前的文章里面提到的观点: 功能测试不建议做自动化 接口测试性价比最高 接口测试可以做自动化 后面所谈到 ...

  6. 从零开始学Python第一周:Python基础(上)

    Python语法基础(上) 一,Python的变量 (1)创建变量 变量的含义:存储信息的地方 创建变量并赋值 x = 1 print x x = 123 #再次赋值 print x (2)使用变量 ...

  7. 翻译《Writing Idiomatic Python》(五):类、上下文管理器、生成器

    原书参考:http://www.jeffknupp.com/blog/2012/10/04/writing-idiomatic-python/ 上一篇:翻译<Writing Idiomatic ...

  8. 翻译《Writing Idiomatic Python》(四):字典、集合、元组

    原书参考:http://www.jeffknupp.com/blog/2012/10/04/writing-idiomatic-python/ 上一篇:翻译<Writing Idiomatic ...

  9. 翻译《Writing Idiomatic Python》(三):变量、字符串、列表

    原书参考:http://www.jeffknupp.com/blog/2012/10/04/writing-idiomatic-python/ 上一篇:翻译<Writing Idiomatic ...

随机推荐

  1. verilog-产生axis数据流

    首先这是产生aixs数据流的代码 `timescale 1ps/1ps `default_nettype none module axis_switch_0_example_master #( ) ( ...

  2. Redis简介与安装

    目录 Redis概述与安装使用 Redis概述与安装使用 Author:SimpleWu GitHub-redis Redis简介 Redis英语全称:( REmote DIctionary Serv ...

  3. kali linux revealed mastering the penetration testing distribution

    1.本博客记载的是这本书的学习笔记,还有出现的一些不懂的单词 我也将会记载这篇博客中.记载顺序是按照本书的章节顺序来记载的.最喜欢本书中的一句   you havae no idea how good ...

  4. Appium Demo

    import unittestimport timefrom appium import webdriverfrom public import configimport os #类继承unittes ...

  5. 阿里云人脸识别测试接口出错 返回Body:{ "errno": 3002, "err_msg": "ILLEGAL_PARAMETERS", "request_id": "672cba83-cf93-4ef4-9ce5-d87e51601632" }

    错误信息如下 返回Body:{ "errno": 3002, "err_msg": "ILLEGAL_PARAMETERS", ...... ...

  6. 滴水穿石-01JAVA和C#的区别

    排名不分先后,想到哪写到哪 1:数组的定义格式不同 java定义: 方式1: ] ; 方式2: ] ; C#中只有方式1 java有两种,C#只有一种 2:继承的实现关键字不同,同时java中实现接口 ...

  7. rpm 命令使用 和 lsof -p 1406 使用

    #安装RPM -v 显示详细信息 -h 显示进度 -i 安装 -U 升级 -q 查询 -ql 查看rpm 包装的文件 - qf 查看命令属于哪个RPM 包 -qi 查看RPM包的详细信息 [root@ ...

  8. xxl系列部署启动通用办法

    http://10.10.6.186:8080/xxl-job-admin # 编译mvn compile # 清理mvn clean # 打包mvn package # 先清理后编译mvn clea ...

  9. GO语言之urfave/cli命令行解析

    练习URL: https://blog.csdn.net/sd653159/article/details/83381786 相信只要部署过线上服务,都知道启动参数一定是必不可少的,当你在不同的网络. ...

  10. java解析html的table

    import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org. ...