python不能导入mysql_python 文件导入mysql

import os

import MySQLdb

rootdir = "e:/20121110"

i = 1

if __name__ == '__main__':

for parent, dirnames, filenames in os.walk(rootdir):

for dirname in dirnames:

print "parent is:" + parent

print "dirname is:" + dirname

for filename in filenames:

print "filename is:" + filename

try:

conn = MySQLdb.connect(host='localhost', user='root', passwd='******', db='lydtest', port=3306)

cur = conn.cursor()

sql = "load data infile 'e:/20121110/" + filename + "' into table taxi fields terminated by ',' enclosed by '\\'' lines terminated by '\\r\\n'";

cur.execute(sql)

conn.commit();

#count = cur.execute('select * from taxi')

print 'the' + str(i) + 'success!'

#print 'there has %s rows record' % count

i = i + 1

cur.close()

conn.close()

except MySQLdb.Error, e:

print "Mysql Error %d: %s" % (e.args[0], e.args[1])

print 'finished!'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值