title: How to access MySQL from multiple threads concurrently
body: <p>We're doing a small benchmark of MySQL where we want to see how it performs for our data.</p>
  
  <p>Part of that test is to see how it works when multiple concurrent threads hammers the server with various queries.</p>
  
  <p>The <a href="http://dev.mysql.com/doc/refman/5.0/en/c.html" rel="noreferrer">MySQL documentation</a> (5.0) isn't really clear about multi threaded clients. I should point out that I do link against the thread safe library (<code>libmysqlclient_r.so</code>)</p>
  
  <p>I'm using prepared statements and do both read (SELECT) and write (UPDATE, INSERT, DELETE). </p>
  
  <ul>
  <li>Should I open one connection per thread? And if so: how do I even do this.. it seems <code>mysql_real_connect()</code> returns the original DB handle which I got when I called <code>mysql_init()</code>)</li>
  <li>If not: how do I make sure results and methods such as <code>mysql_affected_rows</code> returns the correct value instead of colliding with other thread's calls (mutex/locks could work, but it feels wrong)</li>
  </ul>