python & MySQLdb(one)
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)的更多相关文章
- Python爬虫(一)
花了四天的时间用python写了个简单的爬虫程序.整个过程分为两个部分:工具的安装和程序的实现 本文并没有讲程序的详细实现遇到的问题,而是对着手前一些前期的准备 第一部分(工具的安装) 开发工具的下载 ...
- python自动化测试(2)-自动化基本技术原理
python自动化测试(2) 自动化基本技术原理 1 概述 在之前的文章里面提到过:做自动化的首要本领就是要会 透过现象看本质 ,落实到实际的IT工作中就是 透过界面看数据. 掌握上面的这样的本领 ...
- Python小白的发展之路之Python基础(一)
Python基础部分1: 1.Python简介 2.Python 2 or 3,两者的主要区别 3.Python解释器 4.安装Python 5.第一个Python程序 Hello World 6.P ...
- python自动化测试(4)-使用第三方python库技术实现
python自动化测试(4)-使用第三方python库技术实现 1 概述 关于测试的方法论,都是建立在之前的文章里面提到的观点: 功能测试不建议做自动化 接口测试性价比最高 接口测试可以做自动化 ...
- python自动化测试(3)- 自动化框架及工具
python自动化测试(3) 自动化框架及工具 1 概述 手续的关于测试的方法论,都是建立在之前的文章里面提到的观点: 功能测试不建议做自动化 接口测试性价比最高 接口测试可以做自动化 后面所谈到 ...
- 从零开始学Python第一周:Python基础(上)
Python语法基础(上) 一,Python的变量 (1)创建变量 变量的含义:存储信息的地方 创建变量并赋值 x = 1 print x x = 123 #再次赋值 print x (2)使用变量 ...
- 翻译《Writing Idiomatic Python》(五):类、上下文管理器、生成器
原书参考:http://www.jeffknupp.com/blog/2012/10/04/writing-idiomatic-python/ 上一篇:翻译<Writing Idiomatic ...
- 翻译《Writing Idiomatic Python》(四):字典、集合、元组
原书参考:http://www.jeffknupp.com/blog/2012/10/04/writing-idiomatic-python/ 上一篇:翻译<Writing Idiomatic ...
- 翻译《Writing Idiomatic Python》(三):变量、字符串、列表
原书参考:http://www.jeffknupp.com/blog/2012/10/04/writing-idiomatic-python/ 上一篇:翻译<Writing Idiomatic ...
随机推荐
- 安装lrzsz 实现windows与linux之间文件互传
环境:CentOS7.4 执行命令安装: [root@linuxhg01 www]# yum install lrzsz rz // Windows 上传到 linux [root@linuxhg01 ...
- PDF如何去除背景,PDF去除背景颜色
PDF文件在使用的时候大多都是单调的白色背景,但是也有小伙伴再制作PDF文件的时候会给PDF文件添加背景颜色,会有影响文字阅读的情况,这个时候就需要把背景颜色去除了,那么该怎么做呢,不会的小伙们就跟小 ...
- Unity3D用户手册
Unity Manual 用户手册 Welcome to Unity. 欢迎使用Unity. Unity is made to empower users to create the best int ...
- cf14d 树的直径,枚举删边
#include<bits/stdc++.h> using namespace std; #define maxn 300 ]; int n,head[maxn],tot,a,b,dis[ ...
- vue和stylus在subline中显示高亮
首先: 安装这两个插件 Vue Syntax Highlight 和 stylus 1.按住 ctrl + shift + p 2.输入:install Package 3.输入: V ...
- The error may exist in com/bjpowernode/dao/StudentDao.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderExcept
The error may exist in com/bjpowernode/dao/StudentDao.xml### Cause: org.apache.ibatis.builder.Builde ...
- 【C++ Primer 第13章】2. 拷贝控制和资源管理
拷贝控制和资源管理 • 类的行为像一个值.意味着它应该有自己的状态,当我们拷贝一个像值得对象时,副本和原对象是完全独立的,改变副本不会对原对象有任何影响. • 行为像指针的类则共享状态.当我们拷贝一个 ...
- 视频H265格式压缩,软件压缩方法,硬件的没有条件,没法测试。
libx265软压c:/ffmpeg/ffmpeg.exe -i input.mp4 -c:v libx265 -preset:v fast output.mp4 原文件大小:610.87mb 目标文 ...
- 开始写博客,学习Linq(1)
摘自<linq实战>原文: 软件很简单.它可以归结为两件事情:代码和数据. 开发软件却并非那么简单,其中很重要的一项任务就是编写处理数据的代码. 无论选择了哪种语言,在程序开发得某个时候你 ...
- WebApi参数传递实例
Get 1.基础数据类型 1.1方法只含有一个形参 (1)Get传值的本质是通过url字符串拼接(2)Get传递参数本质是url字符串拼接,Request-Head头部传递,Request-Body中 ...