First make sure MacPorts is installed. Then install Python 2.7, MySQL5, the MySQL5 server and the MySQL python library.
Create the default databases by executing the following command:
Start MySQL (once the server has started, press control+c to escape):
Then secure the MySQL server with a password:
Here comes the tricky part. For other languages to access MySQL we will need to create a shortcut to the MySQL socket.
Now the fun of converting a large csv file to a SQL database begins. I'm only using python to do the conversion because the algorithm I wrote for the competition was done in python. If any readers are interested, I can write a quick post on converting in other languages. The rules of the competition forbids me from redistributing the data provided for the competition. So let's use a csv file containing the polling results of the 2008 presidential elections for the rest of this blog post. The data looks something like this:
| State | Obama | McCain | Start | End | Pollster |
|---|---|---|---|---|---|
| AL | 36 | 61 | 27-Oct | 28-Oct | SurveyUSA |
| AL | 34 | 54 | 15-Oct | 16-Oct | Capital Survey |
| AL | 35 | 62 | 8-Oct | 9-Oct | SurveyUSA |
| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
Conceptually, the script is very simple. A connection to the MySQL server is made from python. If the database already exists, it is deleted and a new one is created. The header of the csv file is then used to create fields for the new database. Then the data from the csv file is entered into the database and blank entries are converted to 'None.' The last bit tests the new 'polls' database by pulling all of the polling results from Florida.
Hope this is helpful to someone! You can download all of the files used in this post from here.














