Python连接Mysql数据
#coding=utf-8 import sys import MySQLdb db = MySQLdb.connect("localhost", "root", "root", "test", charset='utf8' ) cursor = db.cursor() sql= "select * from runlist where issendmail=0 limit 1" cursor.execute(sql) data = cursor.fetchone() try: if data!=None: #数据不为空 print(data[1]) except ZeroDivisionError as e: print('发生了异常:',e)
Python简单连接Mysql数据库。