Python3.7和数据库MySQL 8.0.12 数据库SQLite3连接(三)
SQLite3
# SQLite3 嵌入式 数据库 python内置SQLite3
# 导入驱动
import sqlite3 # 创建自增主键的表
msql = "create table user (id integer primary key ,name varchar (20),password varchar (20))"
# 新增数据
msql2 = "insert into user (name,password) values ('Tom','xxxxx')"
# 更新数据
msql3 = "update user set name ='LiLei' where id = 1"
# 查询数据
msql4 = "select id,name,password from user " msql5 = "delete from user where name = \"Tom\"" import sys # 初始化数据库
def InIt_Database():
print("==========初始化数据库")
# 连接数据库 若不存在 则自动创建
mConnection = sqlite3.connect("testsqlite3.db")
mCursor = mConnection.cursor()
try:
mCursor.execute(msql)
except:
# sys.exc_info()会返回一个3值原表(type,value,traceback)
print("数据库已经存在 不可重复创建 异常信息 ERROR=", sys.exc_info()[])
finally:
mConnection.commit()
mCursor.close()
mConnection.close()
print("==========初始化数据库结束") def Insert_test(msql):
print("==========新增数据")
# 连接数据库 若不存在 则自动创建
mConnection = sqlite3.connect("testsqlite3.db")
mCursor = mConnection.cursor()
mCursor.execute(msql)
mConnection.commit()
print("新增一条数据 返回行数:", mCursor.rowcount) mCursor.execute(msql4)
print("==========查询数据库")
for row in mCursor:
print("ID=%s,Name=%s"%(row[],row[]))
mConnection.commit() mCursor.close()
mConnection.close() def Update_test(msql):
# 连接数据库 若不存在 则自动创建
mConnection = sqlite3.connect("testsqlite3.db")
mCursor = mConnection.cursor()
mCursor.execute(msql)
mConnection.commit() mCursor.execute(msql4)
for row in mCursor:
print("ID=%s,Name=%s"%(row[],row[]))
mConnection.commit() mCursor.close()
mConnection.close() def Delete_test(msql):
# 连接数据库 若不存在 则自动创建
mConnection = sqlite3.connect("testsqlite3.db")
mCursor = mConnection.cursor()
mCursor.execute(msql)
mConnection.commit() mCursor.execute(msql4)
for row in mCursor:
print("ID=%s,Name=%s"%(row[],row[]))
mConnection.commit() mCursor.close()
mConnection.close() InIt_Database()
Insert_test(msql2)
Update_test(msql3)
Delete_test(msql5)
Python3.7和数据库MySQL 8.0.12 数据库SQLite3连接(三)的更多相关文章
- Python3.7和数据库MySQL 8.0.12 数据库数据驱动mysql-connector安装(四)
安装mysql-connector驱动 在系统CMD输入命令: pip install mysql-connector 示例: 创建数据库 # 导入驱动 import mysql.connector ...
- Python3.7和数据库MySQL 8.0.12 绿色解压 安装教程(一)
首先要安装MySQL 数据库才可以继续安装图形工具SQLyog 第一步:下载解压包>> MYSQL官网地址:https://dev.mysql.com/downloads/file/?id ...
- MySQL 8.0.12 基于Windows 安装教程(超级详细)
MySQL 8.0.12 基于Windows 安装教程(超级详细) (一步一步来,装不了你找我!) 本教程仅适用Windows系统,如果你原本装了没装上,一定要先删除原本的数据库,执行:mysqld ...
- SQLyog 报错2058 :连接 mysql 8.0.12 解决方法
今天闲来无事,下载新版的 mysql 8.0.12 安装. 为了方便安装查看,我下载了sqlyog 工具 连接 mysql 配置新连接报错:错误号码 2058,分析是 mysql 密码加密方法变了. ...
- mysql 8.0.12 安装配置方法图文教程
一.安装 1.从网上下载MySQL8.0.12版本,下载地址 2. 下载完成后解压 我解压的路径是:D:\Java\mysql-8.0.12-winx64 3. 配置文件 首先在解压的路径下查看是否含 ...
- windows下mysql 8.0.12安装步骤及基本使用教程
本文实例为大家分享了windows下mysql 8.0.12安装步骤及使用教程,供大家参考,具体内容如下 补充:mysql 已经更新到了 8.0.19,大致步骤和这个差不多,照着来就完事了. 我下载的 ...
- Linux安装mysql.8.0.12
1. linux安装mysql8.0.12,亲测可用. 以下是安装过程中出现的问题: 1 [root@localtest1 file]# systemctl start mysqld 2 Job fo ...
- windows 系统如何安装 mysql 8.0.15 数据库?
windows 系统如何安装 mysql 8.0.15 数据库? 1. 下载安装包 下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0. ...
- 云数据库 MySQL 8.0 重磅发布,更适合企业使用场景的RDS数据库
点击订阅新品发布会! 新产品.新版本.新技术.新功能.价格调整,评论在下方,下期更新!关注更多内容,了解更多 最新发布 云数据库MySQL 8.0 升级发布会 2019年5月29日15时,阿里云云数据 ...
随机推荐
- Paper Reading: Stereo DSO
开篇第一篇就写一个paper reading吧,用markdown+vim写东西切换中英文挺麻烦的,有些就偷懒都用英文写了. Stereo DSO: Large-Scale Direct Sparse ...
- javascript 中的number
大家都知道javascript中有五种简单数据类型,number,string,boolean,null,undefined,复杂数据类型是object.本文主要记录下number类型的一些可能不太常 ...
- 微信内嵌浏览器打开手机浏览器下载APP(APK)的方法
想必大家会经常碰到网页链接在微信内无法打开和微信内无法打开app下载页的情况.通常这种情况微信会给个提示 “已停止访问该网址” ,那么导致这个情况的因素有哪些呢,主要有以下四点 1.网页链接被举报次数 ...
- python修炼第二天
第二天的课程还是塞得满满的,一天下来充实也疲惫.那天听出金星师傅嗓子有些沙哑,想必是讲课说话太多导致.啥也不说了.唯有努力练功方可回报! 1 序: 今天主要是详细学习了绝大部分的数据类型,字符编码,边 ...
- 第四章css初识
1.CSS(层叠样式表) 2.CSS语法 选择器{ 属性名1:属性值1: 属性名2:属性值2: } 3.引用CSS的三种方式 第一种:行内样式 例:<a style="color:re ...
- [转] How Bill Gates read books
Bill Gates is one of the most famous figures in the business world. He is one of the richest men in ...
- error: 'retain' is unavailable: not available in automatic reference counting. 解决办法
报错原因是 项目使用的是ARC,但是有非ARC代码. 项目中要混合使用ARC和非ARC. 解决: target -> Build Phases -> Compile Sources 双击报 ...
- MySQL 必知必会学习笔记(常用命令二)
CREATE TABLE students(student_id INT UNSIGNED, name VARCHAR(30), sex CHAR(1), birth DATE, PRIMARY KE ...
- 程序执行流程:猜数字游戏;库的使用:turtle
>>> import turtle >>> turtle.circle(50) >>> turtle.circle(100) Python 3.6 ...
- Problem 2: Even Fibonacci numbers
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting w ...