前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用Python获取Mysql数据

使用Python获取Mysql数据

原创
作者头像
用户7365393
修改2021-11-01 14:01:18
2.4K0
修改2021-11-01 14:01:18
举报
#!/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])
</pre> 

 本文由用户 wuxqing 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。

 转载本站原创文章,请注明出处,并保留原始链接、图片水印。

 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!

 本文地址:https://www.open-open.com/code/view/1457829300325

Python MySQL

6 个评论

ossaa 1年前

Nice post. I was checking constantly this blog and I am impressed! Extremely helpful information specially the last part I care for such info a lot. I was seeking this particular information for a very long time. Thank you and good luck. the travelers within

pevahanifo 3年前

Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for.Carpet Cleaning

cixexey 3年前

I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. suzuki coin

wind-zz 4年前

phyton语言 

cheonghu 5年前 0

#连接数据库
import pymysql;



# 建立mysql链接
def connectdb():

     try:
        conn = pymysql.connect(host='192.168.57.30', port=3306, user='root', passwd='root',
                               db='test', charset='utf8')
     except:
            print("connect db error")
     finally:
         return conn
def getAllDataByTemplatId():  
try:  
conn = db.connectdb() 
 cur = conn.cursor() 
 sql = "SELECT * FROM test uvr"  cur.execute(sql) 
 return cur.fetchall() 
 except:  print("some")  
finally:  print("close db")

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档