首页 > 数据库技术 > 详细

Python2 连接MySQL

时间:2016-05-07 16:40:48      阅读:139      评论:0      收藏:0      [点我收藏+]

先安装MySQL-python

yum install -y MySQL-python

测试代码:

# -*- coding: utf-8 -*-
import os
import MySQLdb

import sys
reload(sys)
sys.setdefaultencoding(utf-8)

conn=MySQLdb.connect(host="127.0.0.1",port=22066,user="root",passwd="123456",db="dsideal_db",charset="utf8")
cursor=conn.cursor()
sql = "SELECT file_name FROM t_resource_info WHERE res_type = 1 AND GROUP_ID = 1 AND RESOURCE_SIZE_INT >10000000 ORDER BY CREATE_TIME LIMIT 1000"
n = cursor.execute(sql)
for row in cursor.fetchall():
        file_id = row[0]
        file_id_2 = file_id[:2]
        path = "/Material/"+file_id_2+"/"+file_id
        if os.path.exists(path):
                print "正在删除文件:"+path
                os.remove(path)
        else:
                print "未找到文件:"+path
print "完成"
cursor.close()

 

Python2 连接MySQL

原文:http://www.cnblogs.com/kgdxpr/p/5468544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!