zoukankan      html  css  js  c++  java
  • python 连接MySQL数据库

      在自动化的测试中,我们常用到mysql数据库中获取到特定的数据与Appium中通过gettext获取到的数据进行对比,来确定数据的显示是否正确,因此我们在自动化的脚本中不可避免的用到了mysql,为确保数据库的安全性,一般公司的数据库将设置SSH来进行连接,但是为了方便自动化测试,可通过专门设置不需要SSH的设置即可连接到数据库。代码贴如下:

    所连接数据库的配置如下:

      

    python连接方式如下:

    # coding=UTF-8
    '''
    Created on 2018年2月26日
    @author: Lucky
    '''
    #import MySQLdb as db
    import pymysql
    
    conn = pymysql.Connect(host="rm-j6c9hc9436gdv2l4j0o.mysql.rds.aliyuncs.com",
                      port= 3306,
                      user = "tester",
                      passwd ="mVNQMCzNs12keh2X8mOuOy2LmMO146Ee",
                      db = "iBer_admin",
                      charset = "utf8")
    Cursor = conn.cursor()
    sql="select mobile from ib_user where mobile = '18392868125'"
    Cursor.execute(sql)
    results = Cursor.fetchone()
    print results
    Cursor.close()
    conn.close()
  • 相关阅读:
    Mysql配置文件模板
    shell命令记录
    SuSE Linux Enterprise Server
    安装jdk1.8
    云南-第一个应用节点-ssh登录-卡顿的问题
    Python重新安装pip
    Centos6.5修改镜像为国内的阿里云源
    supervisord.conf
    Pandas连接Mysql数据库
    Vim速查命令简版
  • 原文地址:https://www.cnblogs.com/syw20170419/p/8473996.html
Copyright © 2011-2022 走看看