Skip to content

Instantly share code, notes, and snippets.

@zs1621
Created January 14, 2014 06:13
Show Gist options
  • Save zs1621/8413867 to your computer and use it in GitHub Desktop.
Save zs1621/8413867 to your computer and use it in GitHub Desktop.
script create 200million lat-lng data to test
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : Rhapsodyzs
# E-mail : zs1213yh@gmail.com
# Date : 14/01/08 11:01:17
# Desc :
#
import MySQLdb
import random
import time
try:
conn = MySQLdb.connect(host='localhost', user='****', passwd='*****', db='test', port=3306)
cur = conn.cursor()
for i in range(2000000):
lat = random.randint(-9000000, 9000000) / 100000.0
lng = random.randint(-18000000,18000000) / 100000.0
user = random.randint(1, 20000)
ctime = time.time() + random.randint(1, 100000)
sql = "insert into `index1` (`lat`, `lng`, `user`, `ctime`) values (%f, %f, %d, %f)" %(lat, lng, user, ctime)
cur.execute(sql)
print "[%d]%s" %(i, sql)
cur.close()
conn.close()
except MySQLdb.Error, e:
print "Mysql Error %d: %s" %(e.args[0], e.args[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment