In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
In order to import data, you can do some processing to the data first. Make it easier to import the database #! / usr/bin/python#coding=utf-8import _ mysql,sys,time# into the data function def add_data (id,name,created_time): try: conn=_mysql.connect ('127.0.0.1) conn.query ("set names utf8") conn.query ("insert into mysql.test3 (% s) values ('% s) values ('% s) '% s') "% ('object_id','object_name','created',id,name,created_time) result=conn.use_result () conn.close () except _ mysql.Error,e: print (" error% dvv% s "% (e.args [0]) E.args [1]) sys.exit (1) if _ _ name__ = "_ _ main__": F = open ("/ opt/testdata/aaa.txt", "r") time1=time.time () print time.ctime () # read the first line of data As the segment name of the datasheet, line=f.readline () content=line.strip (). Split (",") conn0=_mysql.connect ('127.0.0.1) print' connection is builded succesfully' conn0.query ("drop table if exists mysql.test3") conn0.query ("create table mysql.test3 (% s varchar (90),% s varchar (90),% s varchar (90))"% (content [0] [1RV] 1] Content [1] [1conn0.close muri 1], content [2] [1Rue muri 1])) conn0.close () # use next function Let the for loop read the data from the second line next (f) for line in f: # do some processing to separate each segment Put it in a list of content=line.strip (). Split (",") add_data (id=content [0] [1 add_data], name=content [1] [1 add_data], created_time=content [2] [1 add_data 1]) f.close () time2=time.time () print time.ctime () # calculate the time of import data print 'importing time is% favored% (time2-time1)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.