当前位置:Gxlcms > 数据库问题 > 将数据库中数据写入本地文件中

将数据库中数据写入本地文件中

时间:2021-07-01 10:21:17 帮助过:48人阅读

selenium import requests import json from lxml import html # from sgmllib import SGMLParser from lxml import etree import pymysql import mysql_ok phones=1591038300 filename=888mysql_yx.txt ‘‘‘ 从数据库中取数据写到本地文件中 ‘‘‘ mydb = pymysql.connect(host="10.253.125.188", port=3306, user="root", passwd="sjroot", db="user", charset=utf8) mycursor = mydb.cursor() ‘‘‘查询手机号码‘‘‘ # sql = "SELECT phone_tel FROM user.t_user_info where phone_tel like ‘%{}%‘;".format(phones) ‘‘‘查询用户id‘‘‘ # sql = "SELECT t.id,t.phone_tel FROM user.t_user_info t where t.phone_tel like ‘%{}%‘;".format(phones) ‘‘‘查询授信订单号‘‘‘ sql = "SELECT a.app_id FROM bill_data.t_org_br_credit_info a left join user.t_user_info b on a.user_id=b.id " "where a.user_id in (SELECT id FROM user.t_user_info t where " "t.phone_tel like ‘%{}%‘ ) " "order by phone_tel ASC;".format(phones) ‘‘‘查询用信订单号‘‘‘ mycursor.execute(sql) myresult =mycursor.fetchall() fp = open(E:\\apache-jmeter-4.0\\test\\ziyingfiles\\{}.format(filename),w) num_count=0 for x in myresult: num_count+=1 print(phone_tel:, x[0], type(x)) fp.write(x[0] + "\n") fp.close() mycursor.close() mydb.close() print(写入完成,共写入{0}条数据.format(num_count))

 

将数据库中数据写入本地文件中

标签:性能测试   手机号   phone   edit   http   数据   result   HERE   left join   

人气教程排行