Skip to content

Instantly share code, notes, and snippets.

@mportocarrero
Created January 8, 2014 13:12
Show Gist options
  • Select an option

  • Save mportocarrero/8316565 to your computer and use it in GitHub Desktop.

Select an option

Save mportocarrero/8316565 to your computer and use it in GitHub Desktop.
Creating table - Python (pymsql) I created a table called "bike" with the columns: "Borough", "Date", "Latitude", "Longitude", "Area" and "Investigation". To set up the data type for each column, I had a look online and found out which data type would best suit my purposes. Ended up finding about DECIMAL and the meaning of the values inside brac…
import pymysql, sys
try:
conn = pymysql.connect(host='localhost',
port=3306,
user='co302mc',
passwd='mafol597',
db='co302mc_bike_theft')
cur = conn.cursor()
cur.execute("CREATE TABLE bike (Id INT PRIMARY KEY AUTO_INCREMENT, Borough VARCHAR(20), Date DATE, Latitude DECIMAL(10, 8) NOT NULL, Longitude DECIMAL(10, 8) NOT NULL, Area VARCHAR(100), Investigaton VARCHAR(100))")
data = cur.fetchall()
print data
except Exception as e:
print "couldn't connect to database",e
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment