• python 操作mysql


    import mysql.connector 
    import xlrd
    mydb=mysql.connector.connect(host="125.65.*.*",user="pjump",passwd="******",database="pjump")
    mycursor=mydb.cursor()
    #mycursor.execute("create table pytest (id VARCHAR(255),domian VARCHAR(255))")
    #mycursor.execute("show tables")
    #mycursor.execute("drop table pytest")
    workbook=xlrd.open_workbook(r"e:domain.xls")
    table=workbook.sheet_by_name('Sheet1')
    domainlist=[]
    s=()
    for m in range(table.nrows):
        if m<table.nrows and m>0:
            s=(int(table.cell(m,0).value),table.cell(m,1).value)
            domainlist.append(s)
    #print (domainlist)        
    
    # #@@@@@@@@@@@@@@插入@@@@@@@@@@
    # sql= "insert into pytest (id,domian) values (%s,%s)"
    # mycursor.executemany(sql,domainlist)
    # mydb.commit()
    # #@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    # #@@@@@@@@@@@@执行查询@@@@@@@@
    # sql='select *from pytest'
    # mycursor.execute(sql)
    # result= mycursor.fetchall()
    # #fetchone 查询结果第一条,fetchall  所有查询结果
    # for x in result:
    #     print (x)
    # #@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    #@@@@@@@@@@@@@@@@@@@删除@@@@@@@@@
    #sql='dorp table if exists pytest'
    # mycursor.execute(sql)
    #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    
    #@@@@@@@@@@@@@@@@@@@删除@@@@@@@@@
    #sql='update pytest set domain = %s where domain = %s'
    #val = ("baidu.com","qq.com")
    #mycursor.execute(sql,val)
    #mydb.commit()
    #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    修改更新操作时注意mydb.commit() 操作

  • 相关阅读:
    vim技巧2
    vim技巧1
    网站压力测试工具
    CentOS mysql安装
    破解root
    渐进式性能监测案例
    网络监测介绍
    I/O检测介绍
    虚拟内存介绍
    @Slf4j
  • 原文地址:https://www.cnblogs.com/plefan/p/13924332.html
Copyright © 2020-2023  润新知