<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Field Guide to Programmers &#187; MySQL</title>
	<atom:link href="http://www.fieldguidetoprogrammers.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fieldguidetoprogrammers.com</link>
	<description>Code, Toys, Bits of Odd Fluff</description>
	<lastBuildDate>Fri, 19 Jun 2009 16:05:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple MySQL Python Example</title>
		<link>http://www.fieldguidetoprogrammers.com/python/simple-mysql-python-example/</link>
		<comments>http://www.fieldguidetoprogrammers.com/python/simple-mysql-python-example/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 12:50:05 +0000</pubDate>
		<dc:creator>jamiegrove</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.fieldguidetoprogrammers.com/blog/python/simple-mysql-python-example/</guid>
		<description><![CDATA[In order to use MySQL with python, you need to get the MySQLdb up and running. Once you have that installed, you use the DB-API to perform queries and such. The DB-API PEP is good if you already know what you&#8217;re doing (you can also look at the sqlite module doc). Below is my very [...]]]></description>
			<content:encoded><![CDATA[<p>In order to use MySQL with python, you need to get the <a href="http://mysql-python.sourceforge.net/">MySQLdb</a> up and running.  Once you have that installed, you use the <a href="http://www.python.org/dev/peps/pep-0249/">DB-API</a> to perform queries and such.</p>
<p>The DB-API PEP is good if you already know what you&#8217;re doing (you can also look at the <a href="http://docs.python.org/lib/module-sqlite3.html">sqlite module doc</a>).  Below is my <i>very</i> simple example.  Paul DuBois has an extensive article on <a href="http://www.kitebird.com/articles/pydbapi.html">using MySQL with python</a>.</p>
<pre class="codebox">
from MySQLdb import *

# connect to the database
conn = connect(
	host='localhost',
	user='test',
	db='test'
)

table_def = """
CREATE TABLE samples (
	sample_id int PRIMARY KEY,
	sample_name varchar(20),
	sample_url varchar(250)
)
"""

try:
	cursor = conn.cursor()
	cursor.execute(table_def)
	conn.commit()
except:
	print 'Table already exists.' #obviously, there could be other errors too.

conn.close()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fieldguidetoprogrammers.com/python/simple-mysql-python-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
