title: How to connect to MySQL database with C++ (ubuntu)
body: <p>I'm not sure how to connect to a MySQL database using C++ on Ubuntu Linux.
  Specifically, I want to be able to create a database called "<strong>new</strong>". I'm not sure where to put the query. Below is the code I'm using. </p>
  
  <p><strong>driver = get_driver_instance();</strong> gives me the error message <strong>undefined reference to 'get_driver_instance'</strong></p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include "mysql_driver.h"
  #include "mysql_connection.h"
  #include &lt;cppconn/driver.h&gt;
  #include &lt;cppconn/exception.h&gt;
  #include &lt;cppconn/resultset.h&gt;
  #include &lt;cppconn/statement.h&gt;
  using namespace std;
  
  int main(int argc, char** argv) {
  
  cout &lt;&lt; endl;
  cout &lt;&lt; "Running 'SELECT 'Hello World!' AS _message'..." &lt;&lt; endl;
  
  try {
    sql::Driver *driver;
    sql::Connection *con;
    sql::Statement *stmt;
    sql::ResultSet *res;
  
   /* Create a connection */
   driver = get_driver_instance();
   /* Write your own driver details */
   con = driver-&gt;connect("tcp://127.0.0.1:3306", "root", "pass");
   /* Connect to the MySQL test database */
   con-&gt;setSchema("test");
  
   stmt = con-&gt;createStatement();
   res = stmt-&gt;executeQuery("SELECT 'Hello World!' AS _message");
   while (res-&gt;next()) {
     cout &lt;&lt; "\t... MySQL replies: ";
   /* Access column data by alias or column name */
  cout &lt;&lt; res-&gt;getString("_message") &lt;&lt; endl;
  cout &lt;&lt; "\t... MySQL says it again: ";
  /* Access column data by numeric offset, 1 is the first column */
  cout &lt;&lt; res-&gt;getString(1) &lt;&lt; endl;
  }
  delete res;
  delete stmt;
  delete con;
  
  }catch (sql::SQLException &amp;e) {
    cout &lt;&lt; "# ERR: SQLException in " &lt;&lt; __FILE__;
    cout &lt;&lt; "(" &lt;&lt; __FUNCTION__ &lt;&lt; ") on line ";
    cout  &lt;&lt; __LINE__ &lt;&lt; endl;
    cout &lt;&lt; "# ERR: " &lt;&lt; e.what();
    cout &lt;&lt; " (MySQL error code: " &lt;&lt; e.getErrorCode();
    cout &lt;&lt; ", SQLState: " &lt;&lt; e.getSQLState() &lt;&lt; " )" &lt;&lt; endl;
  }
  
   cout &lt;&lt; endl;
  
   return EXIT_SUCCESS;
  }
  </code></pre>