123456789101112131415161718192021222324252627 |
- #!/usr/bin/python3
- # -*- coding: utf-8 -*-
- # import pymysql
- import mysql.connector
- import json
- # mysql -ueq -h192.168.61.42 -P3306 -p'Xdmy@1234' eq
- db = mysql.connector.connect(host='222.73.129.15',
- user='root',
- passwd='kepaiteng!QAZ',
- db='eq',
- port=31306)
- # db = mysql.connector.connect(host='192.168.61.42',
- # user='eq',
- # passwd='Xdmy@1234',
- # db='eq',
- # port=3306)
- # tname="buydetail"
- # tname=input("请输入表名:")
- tname="parts"
- 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()
|