1234567891011121314151617181920 |
- #!/usr/bin/python3
- # -*- coding: utf-8 -*-
- # import pymysql
- import mysql.connector
- import json
- db = mysql.connector.connect(host='222.73.129.15',
- user='root',
- passwd='kepaiteng!QAZ',
- db='eq',
- port=31306)
- # tname="buydetail"
- tname=input("请输入表名:")
- cursor = db.cursor(dictionary=True)
- err =cursor.execute("select * from %s limit 1"%(tname))
- result =cursor.fetchall()
- print(f"json: {json.dumps(result, indent=4, sort_keys=True, default=str)}")
- # write_file = open("%s.json"%(tname), "w", encoding="utf-8").write(sqlstr)
- print(err)
- db.close()
|