navicat 和 pymysql

时间:2023-01-07 11:54:08

---------------------------------------------------相信时间的力量,单每月经过努力的时间,一切的安排都是懊脑的安排.

# # -------------------------------*******************-------------------------------

day039 通过pymysql来添加修改数据

import pymysql

conn = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='666',
database='day02',
charset='utf8'
)
# cursor = conn.cursor()
cursor = conn.cursor(pymysql.cursors.DictCursor)
# sql = "select * from userinfo where username='%s' and pword='%s';"%(username,password)
# sql = "select * from userinfo where username=%s and pword=%s;"
# sql = "insert into userinfo(username,pword) values(%s,%s);"
# sql = "update userinfo set pword='666666' where username='文杰';"
sql = "select * from userinfo;"
print(sql)
res = cursor.execute(sql)
# res = cursor.executemany(sql,[('文杰','666'),('鸿洁','666')])
print(res)
print(cursor.fetchall()) conn.commit()
# # --------------[通过SQL注入]--------------
import pymysql

conn = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='666',
database='day02',
charset='utf8'
) username = input('请输入用户名:')
password = input('请输入密码:') cursor = conn.cursor()
# sql = "select * from userinfo where username='%s' and pword='%s';"%(username,password)
sql = "select * from userinfo where username=%s and pword=%s;"
print(sql)
res = cursor.execute(sql,[username,password])
print('受影响的行数:',res)
if res:
print('登录成功')
else:
print('用户名或者密码不对')
# # --------------[pymysql的简单使用]--------------

import pymysql

conn = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='666',
database='day02',
charset='utf8'
) username = input('请输入用户名:')
password = input('请输入密码:') cursor = conn.cursor()
sql = "select * from userinfo where username='%s' and pword='%s';"%(username,password)
print(sql)
res = cursor.execute(sql)
print(res)
# print(cursor.fetchone())
# print(cursor.fetchmany(2))
print(cursor.fetchmany(5))
print('xxxxxxxxxx')
cursor.scroll(3,'absolute')
# cursor.scroll(3,'relative') print(cursor.fetchone())

阅读目录

参考链接 https://www.cnblogs.com/clschao/articles/10023248.html

掌握:
#1. 测试+链接数据库
#2. 新建库
#3. 新建表,新增字段+类型+约束
#4. 设计表:外键
#5. 新建查询
#6. 备份库/表

#注意:
批量加注释:ctrl+?键
批量去注释:ctrl+shift+?键

 增、删、改:conn.commit()

    查操作在上面已经说完了,我们来看一下增删改,也要注意,sql语句不要自己拼接,交给excute来拼接

navicat  和  pymysql
navicat  和  pymysql
import pymysql
#链接
conn=pymysql.connect(host='localhost',port='3306',user='root',password='123',database='crm',charset='utf8')
#游标
cursor=conn.cursor() #执行sql语句
#part1
# sql='insert into userinfo(name,password) values("root","123456");'
# res=cursor.execute(sql) #执行sql语句,返回sql影响成功的行数
# print(res)
# print(cursor.lastrowid) #返回的是你插入的这条记录是到了第几条了 #part2
# sql='insert into userinfo(name,password) values(%s,%s);'
# res=cursor.execute(sql,("root","123456")) #执行sql语句,返回sql影响成功的行数
# print(res)
#还可以进行更改操作:
#res=cursor.excute("update userinfo set username='taibaisb' where id=2")
#print(res) #结果为1
#part3
sql='insert into userinfo(name,password) values(%s,%s);'
res=cursor.executemany(sql,[("root","123456"),("lhf","12356"),("eee","156")]) #执行sql语句,返回sql影响成功的行数,一次插多条记录
print(res)
#上面的几步,虽然都有返回结果,也就是那个受影响的函数res,但是你去数据库里面一看,并没有保存到数据库里面,
conn.commit() #必须执行conn.commit,注意是conn,不是cursor,执行这句提交后才发现表中插入记录成功,没有这句,上面的这几步操作其实都没有成功保存。
cursor.close()
conn.close()
navicat  和  pymysql
navicat  和  pymysql

  四 查:fetchone,fetchmany,fetchall

    navicat  和  pymysql

navicat  和  pymysql
navicat  和  pymysql
import pymysql
#链接
conn=pymysql.connect(host='localhost',user='root',password='123',database='egon')
#游标
cursor=conn.cursor() #执行sql语句
sql='select * from userinfo;'
rows=cursor.execute(sql) #执行sql语句,返回sql影响成功的行数rows,将结果放入一个集合,等待被查询 # cursor.scroll(3,mode='absolute') # 相对绝对位置移动
# cursor.scroll(3,mode='relative') # 相对当前位置移动
res1=cursor.fetchone()
res2=cursor.fetchone()
res3=cursor.fetchone()
res4=cursor.fetchmany(2)
res5=cursor.fetchall()
print(res1)
print(res2)
print(res3)
print(res4)
print(res5)
print('%s rows in set (0.00 sec)' %rows) conn.commit() #提交后才发现表中插入记录成功
cursor.close()
conn.close() '''
(1, 'root', '123456')
(2, 'root', '123456')
(3, 'root', '123456')
((4, 'root', '123456'), (5, 'root', '123456'))
((6, 'root', '123456'), (7, 'lhf', '12356'), (8, 'eee', '156'))
rows in set (0.00 sec)
'''
navicat  和  pymysql

navicat 和 pymysql的更多相关文章

  1. navicat工具 pymysql模块

    目录 一 IDE工具介绍(Navicat) 二 pymysql模块 一 IDE工具介绍(Navicat) 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具,我们使用Navi ...

  2. 数据库——可视化工具Navicat、pymysql模块、sql注入问题

    数据库--可视化工具Navicat.pymysql模块.sql注入问题 Navicat可视化工具 Navicat是数据库的一个可视化工具,可直接在百度搜索下载安装,它可以通过鼠标"点点点&q ...

  3. 数据库 - Navicat与pymysql模块

    一.Nabicat 在生产环境中操作MySQL数据库还是推荐使用命令行工具mysql,但在我们自己开发测试时, 可以使用可视化工具Navicat,以图形界面的形式操作MySQL数据库 官网下载:htt ...

  4. MySQL多表查询,Navicat使用,pymysql模块,sql注入问题

    一.多表查询 #建表 create table dep( id int, name varchar(20) ); create table emp( id int primary key auto_i ...

  5. navicat 使用 pymysql模块

    新健库 ,新增字段+类型+约束 设计表:外键(自增) 新建查询 建立表模型 /* 数据导入: Navicat Premium Data Transfer Source Server : localho ...

  6. navicat和pymysql

    内容回顾 select distinct 字段1,字段2,...from 表名 where 分组之前的过滤条件 group by 分组条件 having 分组之后过滤条件 order by 排序字段1 ...

  7. day038 navicat pymysql

    今日内容: 1.navicat 2.pymysql 1.navicat 需要掌握 #1. 测试+链接数据库 #2. 新建库 #3. 新建表,新增字段+类型+约束 #4. 设计表:外键 #5. 新建查询 ...

  8. day44 mysql高级部分内容

    复习 1.多表查询 2.navicat 3.pymysql 1.视图 ***(是一个虚拟表,非真实存在的) 引子 select * from emp left join dep on emp.dep_ ...

  9. 老师的blog整理 .网络编程部分 .网络编程部分 前端部分 django基础部分

    老师的blog整理 python基础部分: 宝哥blog: https://www.cnblogs.com/guobaoyuan/ 开哥blog: https://home.cnblogs.com/u ...

随机推荐

  1. 坦克大战,看你能坚持几秒 ~~Duang~~Duang

    闲来无事,写了一个坦克大战的小游戏,打开页面就能看到源码,代码还没有来得及整理.大家闲来玩玩吧,看谁玩的时间长! http://xiaohaibaomu.com/home/index

  2. day5 -指针

    指针和指针变量 指针就是地址,地址就是指针 地址就是存放单元的编号 指针变量是存放地址的变量 指针和指针变量是两个不同的概念,但是要注意,通常我们叙述时会把指针变量简称为指针,实际他们含义并不一样 指 ...

  3. js检测浏览器屏幕宽度

    使用javascript脚本编写的一个能检测浏览器屏幕的宽度,当改变浏览器屏幕大小时,输出的数值也会随之改变.

  4. 采用p6spy完整显示hibernate的SQL语句

    虽然在hibernate中有show_sql选项,但是显示出来的语句大多类似 select * from xxx where value=? 但是有时候我们需要得到完整的SQL语句,怎么办呢?使用P6 ...

  5. VirtualBox的四种网络连接方式详解

    VirtualBox中有4中网络连接方式: 1. NAT 2. Bridged Adapter 3. Internal 4. Host-only Adapter VMWare中有三种,其实他跟VMWa ...

  6. 【python】python支持中文变量,醉了

    哈哈 = 1 呜呜 = -1 哈哈 + 呜呜 = 0

  7. POJ 2942 Knights of the Round Table - from lanshui_Yang

    Description Being a knight is a very attractive career: searching for the Holy Grail, saving damsels ...

  8. [array] leetcode - 31. Next Permutation - Medium

    leetcode - 31. Next Permutation - Medium descrition Implement next permutation, which rearranges num ...

  9. 带吸附效果的ViewPager(一)

    什么叫吸附效果?先看一个示例更为直观,借用网上的一个效果图: 类似这种效果的app很多,网上的实现方法也是很多,但各种重写各种监听又令人不胜其烦,今日突发奇想,顺着自己的思路实现了类似的效果,不敢独享 ...

  10. Unity3D 代码加密保护工具

    加密方式   对于Unity3D的保护方式,主要是通过Virbox Protector Standalone对Unity3D程序的整个生成目录进行加密,可以保护Unity的主要代码逻辑不被反编译,最大 ...