Python写的链接数据库存取数据

Python写的链接数据库存取数据

#!/usr/bin/python
# -*- coding: UTF-8 -*-
from __future__ import print_function
import os
import sys
import time
import MySQLdb

jscookid=sys.argv[1]
# 打开数据库连接
conn = MySQLdb.connect(host="mysql.feieryun.cn",port=3324,user="feieryun",passwd="feieryun",db="firadio_ssproxy",charset="utf8")

# 使用cursor()方法获取操作游标
#cursor = conn.cursor()
#cursor2 = conn.cursor()

# 使用execute方法执行SQL语句
#cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取一条数据
#data = cursor.fetchone()

def test():
  cursor = conn.cursor()
  cursor.callproc('proc_port_fetch',[1])
  rows = cursor.fetchall()
  cursor.close()
  cursor2 = conn.cursor()
  for row in rows:
    #print row
    os.system('python mujson_mgr.py -a -u '+bytes(row[1])+' -p '+bytes(row[1])+' -k '+row[2]+' -m aes-256-cfb -O origin -o plain -t '+bytes(row[3]))
    os.system('python mujson_mgr.py -e -u '+bytes(row[1])+' -p '+bytes(row[1])+' -k '+row[2]+' -m aes-256-cfb -O origin -o plain -t '+bytes(row[3]))
    cursor2.callproc('proc_port_fetched',[jscookid,row[0]])
  cursor.close()
  conn.commit()

while True:
  test()
  print('.', end='')
  sys.stdout.flush()
  time.sleep(1)

# 关闭数据库连接
conn.close()

 

posted on 2017-11-28 15:46  项希盛  阅读(507)  评论(0编辑  收藏  举报