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数据库。

posted @ 2019-06-13 09:39  小华的PYTHON  阅读(135)  评论(0编辑  收藏  举报