一个简单的python数据库脚本

   

脚本的作用很简单,只是进数据库取个数。

# yum install python3
# python3 -m pip install PyMySQL
#!/usr/bin/python3
import pymysql
#conn = pymysql.connect(host="127.0.0.1", user=“zabbix”,password=”passwd”,database=“zabbix”,charset=“utf8”)
conn = pymysql.connect('localhost','zabbix','passwd','zabbix')
cursor = conn.cursor()
sql = "SELECT value FROM `history_text`order by clock desc limit 1"
cursor.execute(sql)
data = cursor.fetchone()
print ("Database version : %s " % data)
cursor.close()
conn.close()

发表评论