title: How to parse MySQL built-code from within Python?
body: <p><a href="http://dl.dropbox.com/u/5207386/builtcode.sql" rel="nofollow">I've exported my MySQL database to a .txt/.sql file (link)</a> and want to use this to rebuilt the database on other computers. While running the script in HeidiSQL works perfectly fine, I want to make sure all the tables exist and are correct before starting my application.</p>
  
  <p>I could copy paste the built code into my Python code, but the export is a direct representation of my database and shouldn't contain any errors, whereas copy-pasting... So instead I tried parsing the file, but my parsing skills leave a lot to be desired.</p>
  
  <p>Here's a snippet of the code:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `data` (
    `dataid` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `measurementid` int(10) unsigned NOT NULL DEFAULT '0',
    `frame` int(10) unsigned NOT NULL,
    `sensor_row` int(10) unsigned NOT NULL,
    `sensor_col` int(10) unsigned NOT NULL,
    `value` float unsigned NOT NULL,
    PRIMARY KEY (`dataid`),
    UNIQUE KEY `measurementid_frame_sensor_row_sensor_col` (`measurementid`,`frame`,`sensor_row`,`sensor_col`)
  ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>So assuming the database <code>data</code> is already created, I'm looking for a way to parse the built code and <strong>create</strong> all the required tables if they don't exist or <strong>alter</strong> them if they've changed. </p>
  
  <p>Any suggestions on how to approach this?</p>