title: Access mysql from perl using odbc
body: <p>I need to access MySQL from perl.  </p>
  
  <p><strong>Can I connect using the <code>odbc</code> driver?</strong></p>
  
  <p><strong>If so, how do I do that?</strong></p>
  
  <p>I just can't seem to get the connection string right!</p>
  
  <p>On windows, where <code>DBD:MySQL</code> is available, this is how I connected:</p>
  
  <pre><code>DBI-&gt;connect("DBI:mysql:$database", 
      $user, $password, {RaiseError =&gt; 1});
  </code></pre>
  
  <p>This is what I've tried:</p>
  
  <pre><code>DBI-&gt;connect("DBI:ODBC:$database", $user, $password, {RaiseError =&gt; 1});'
  </code></pre>
  
  <p>This results in the following error:</p>
  
  <blockquote>
    <p>DBI connect('database','username',...) failed: [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded (SQL-IM002) at -e line 1</p>
  </blockquote>
  
  <p>This is a standard connection on a local machine -- that is, both the perl app and the MySQL server are on the same machine.</p>
  
  <hr>
  
  <p>I'd like to use <code>odbc</code> because <code>DBD:mysql</code> <a href="http://code.activestate.com/ppm/DBD-mysql/" rel="nofollow">doesn't build</a> for ActiveState perl on Mac OS X, and it's much easier for us when we stick with packages that can be obtained through ppm.</p>