使用Python获取Mysql数据
2018-07-20 来源:open-open
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# pip install MySQL-python
import MySQLdb, os
try:
conn = MySQLdb.connect(host='172.17.42.1', user='数据库访问用户', passwd='数据库访问密码', db='数据库名', port=3306)
cur = conn.cursor()
cur.execute('SELECT `id`, `name`, `path`, FROM `doc_file`')
# 获取全部记录
results=cur.fetchall()
for r in results:
id, name, path = r[0], r[1], r[2]
if path and not os.path.exists(path):
print 'file not exist: ', id, name, path, flashpath
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
下一篇: Java经典问题算法大全
最新资讯
热门推荐