继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

python 操作MySQL数据库

所谓伊人_在水一方
关注TA
已关注
手记 273
粉丝 23
获赞 169

1.connect

def conn(ip,user,password,database):

    con = mdb.connect(ip,user,password,database)

    cur = con.cursor()

    return cur


2.select
SELECT ip,env from hosts ORDER BY 1, 2
for row in cur.fetchall():
print row
('172.x.x.x', 'prod')

('PROBLEM: 172.x.x.x Table open cache too small\r\nservice_name: Table open cache too small\r\nService_status: PROBLEM\r\nService_severity: Information\r\nItem values:\r\nCheck_service_ip:172.x.x.x\r\nCheck_service_name:mysql.status[Open_tables]\r\nCheck_service_vlaue:4059\r\nCheck_service_time:2018.03.01 09:54:43',)

3.update

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP