excle.py 963 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. # import pymysql
  4. import mysql.connector
  5. import json
  6. # mysql -ueq -h192.168.61.42 -P3306 -p'Xdmy@1234' eq
  7. db = mysql.connector.connect(host='222.73.129.15',
  8. user='root',
  9. passwd='kepaiteng!QAZ',
  10. db='eq',
  11. port=31306)
  12. # db = mysql.connector.connect(host='192.168.61.42',
  13. # user='eq',
  14. # passwd='Xdmy@1234',
  15. # db='eq',
  16. # port=3306)
  17. # tname="buydetail"
  18. # tname=input("请输入表名:")
  19. tname="parts"
  20. cursor = db.cursor(dictionary=True)
  21. err =cursor.execute("select * from %s limit 1"%(tname))
  22. result =cursor.fetchall()
  23. print(f"json: {json.dumps(result, indent=4, sort_keys=True, default=str)}")
  24. # write_file = open("%s.json"%(tname), "w", encoding="utf-8").write(sqlstr)
  25. print(err)
  26. db.close()