title: Why is Hibernate not creating database for MySQL?
body: <p>I have following hibernate.cfg.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
  
          &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/userdb&lt;/property&gt;
          &lt;property name="connection.username"&gt;root&lt;/property&gt;
          &lt;property name="connection.password"&gt;1234&lt;/property&gt;
          &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/property&gt;
  
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
          &lt;property name="format_sql"&gt;true&lt;/property&gt;
          &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
          &lt;mapping class="com.beingjavaguys.hbn.User" /&gt;
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>I tryed another dialect(<code>org.hibernate.dialect.MySQLDialect</code>) but I see old result</p>
  
  <p>pom.xml:</p>
  
  <pre><code>...
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;4.0.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
              &lt;version&gt;4.2.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.common&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-commons-annotations&lt;/artifactId&gt;
              &lt;version&gt;4.0.1.Final&lt;/version&gt;
              &lt;classifier&gt;tests&lt;/classifier&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpa-2.0-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;4.0.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.validation&lt;/groupId&gt;
              &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.0.GA&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.27&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>When invokes following code line:</p>
  
  <pre><code>    return new Configuration().configure().buildSessionFactory();
  </code></pre>
  
  <p>I see following stacktrace:</p>
  
  <pre><code>ERROR: HHH000231: Schema export unsuccessful
  com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'userdb'
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      ...
      at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
      at org.hibernate.tool.hbm2ddl.DatabaseExporter.&lt;init&gt;(DatabaseExporter.java:52)
      at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:368)
      at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:305)
      at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:294)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:452)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
      at com.beingjavaguys.hbn.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)
      at com.beingjavaguys.hbn.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:12)
      at com.beingjavaguys.hbn.App.saveUser(App.java:45)
      at com.beingjavaguys.hbn.App.main(App.java:30)
  </code></pre>
  
  <p>What the reason of this problem?</p>
  
  <p>How to fix it?</p>
  
  <h2>P.S.</h2>
  
  <p>database schema doesn't exist in MySql!</p>
  
  <p>if I add Database shema explicitly - all works good.</p>
  
  <h2> Is where way to create schema from java application?</h2>