首页 > 数据库 >UI自动化-MySQL

UI自动化-MySQL

时间:2023-03-27 21:12:53浏览次数:33  
标签:database self MySQL cursor host UI 自动化 password port

import pymysql
'''
连接mysql数据库参数
:param host: Host where the database server is located
:param user: Username to log in as
:param password: Password to use.
:param database: Database to use, None to not use a particular one.
:param port: MySQL port to use, default is usually OK. (default: 3306)
'''
#创建一个数据库的连接对象
db=pymysql.Connect(host='192.168.2.113',
                   user='root',
                   password='123456',
                   database='duoceshi',
                   port=3306)
#游标对象的2个作用:
#1.执行sql语句
#2.把执行的结果返回保存到cursor游标对象中
#创建一个mysql数据库游标对象
cursor=db.cursor()
# cursor.execute('select * from cc;')
#返回表中第一行数据
# one=cursor.fetchone()             #fetchone()方法返回表中第一行
# print(one)
# print(type(one))
#插入数据
# insert_sql='insert into cc(s_id,score)values(2,88),(3,89);'
# cursor.execute(insert_sql)
# cursor.execute('select * from cc;')   #插入数据进行查询
# all=cursor.fetchall()              #fetchall()  方法是返回表中所有数据
# print(all)


#上面写的都是属于线性脚本
#把线性脚本进行封装
import pymysql
class   Db_utils():
    def __init__(self,host,user,password,database,port):
        self.host=host              #ip地址
        self.user=user              #用户名
        self.password=password      #密码
        self.database=database      #库
        self.port=port              #端口3306
    def connect(self):
        self.db=pymysql.Connect(host=self.host,
                                user=self.user,
                                password=self.password,
                                database=self.database,
                                port=self.port)
        self.cursor=self.db.cursor()        # 创建一个mysql数据库游标对象
    def excute(self,sql):
        self.cursor.execute(sql)
    def fetchone(self):
        print(self.cursor.fetchone())        # fetchone()方法返回表中第一行数据
    def fetchall(self):
        print(self.cursor.fetchall())        # fetchone()方法返回表中全部数据
if __name__ == '__main__':
    d=Db_utils(host='192.168.0.178',
                   user='root',
                   password='123456',
                   database='duoceshi',
                   port=3306)
    d.connect()          
    d.excute('select * from cc;')
    d.fetchone()
    d.fetchall()

 

标签:database,self,MySQL,cursor,host,UI,自动化,password,port
From: https://www.cnblogs.com/jjm414/p/17262861.html

相关文章

  • MySQL 中索引是如何实现的,有哪些类型的索引,如何进行优化索引
    MySQL中的索引前言索引的实现哈希索引全文索引B+树索引索引的分类聚簇索引(clusteredindex)非聚簇索引(non-clusteredindex)联合索引覆盖索引回表查询......
  • remote server can't connect mysql
    最近,在写node项目时,远程服务器在连接mysql数据库时,出现一下问题:  解决此问题:1)    2)  具体详看:https://stackoverflow.com/questions/3791694......
  • 如何单机部署多个 MySQL 8.0 实例 ?
    在服务器资源有限的情况下,可利用该方案快速搭建各类mysql架构方案。各MySQL实例共享一个mysqld主程序,但各实例数据目录是独立的,存放在不同的文件夹中;好了、废话不多......
  • MySQL的DML操作
    总结:DML操作是对数据进行操作不会对表结构进行操作基本功能:插入insert删除:delete更新:update代码:--2.DML数据库操作--基本功能 插入insert 删除delete ......
  • vue2+element-ui+springboot+mybatis-plus获取当前账户进行修改密码详细教程
    以下内容仅供学习使用新建一个dto类,用于专门修改当前账户的使用importlombok.Data;@DatapublicclassUserPasswordDTO{privateStringusername;priva......
  • Python3 导入 excel 到 MySQL 数据库
    不必细说的背景最近在做一个Java项目,需要处理一批历史数据,由于工具限制,采用了Python导入excel到数据库的方式。 安装依赖包pipinstallpandaspipinstal......
  • .NET Task 揭秘(3)async 与 AsyncMethodBuilder
    目录前言AsyncMethodBuilder介绍AsyncMethodBuilder是状态机的重要组成部分AsyncMethodBuilder的结构AsyncMethodBuilder功能分析对状态机的生命周期进行管理......
  • iOS7应用开发6:UINavigation, UITabbar控制器的多态性
    1、前期所实现的PlayingCard游戏,其ViewController只能适应PlayingCard这一种游戏规则。而将createDeck函数修改为返回一个nil后,整个ViewController与PlayingCard就没有关......
  • 永洪BI、瓴羊Quick BI领衔国产BI工具
    数据时代下,新BI工具成为推动企业向数字化转型发展的重要工具。这些BI工具既有国外引进的软件,也有国产软件。国产BI工具的功能性、优越性等,已在大量实践应用中得到验证。其中......
  • MySQL面经
    内容援引自JavaGuide、哔哩哔哩黑马程序员数据库从入门到精通,感谢各位大神原创分享数据库Mysql常见的关系型数据库包括mysql、SQLServer、Oracle、常见的非关系型数据库......