Grails continues using HSQLDB instead of switching to MySQL configuration

I’m working through a Grails tutorial and trying to switch my database from HSQLDB to MySQL. I’m using Grails version 1.2.1 and have updated my DataSource.groovy file to configure MySQL settings.

Here’s my current DataSource.groovy configuration:

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://localhost/bookstore"
    dbCreate = "create"
    username = "bookapp"
    password = "bookapp"
    dialect = org.hibernate.dialect.MySQL5InnoDBDialect
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
environments {
    development {
    }
    test {
    }
    production {
    }
}

The application starts without errors when I run grails run-app, but when I try to access any page that hits the database, I encounter this error:

java.sql.SQLException: Table not found in statement [select this_.id as id1_0_, this_.version as version1_0_, this_.name as name1_0_, this_.category as category1_0_ from book this_ limit ?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at bookstore.BookController$_closure1.doCall(script1269434425504953491149.groovy:8)

The error clearly indicates that it’s still trying to use HSQLDB. My MySQL database remains empty with no tables created.

I’ve already tried:

  • Adding the MySQL connector JAR to the lib folder
  • Running grails clean
  • Moving the dataSource config into the development environment block

Why does Grails keep using HSQLDB despite my MySQL configuration?

Had this exact same issue learning Grails years ago. You’re missing the MySQL dependency in your BuildConfig.groovy file. Just dropping the JAR in the lib folder isn’t enough - Grails 1.2.1 needs it properly declared in the build config. Open grails-app/conf/BuildConfig.groovy and add this to the dependencies section: runtime ‘mysql:mysql-connector-java:5.1.13’. Then run grails clean and grails compile to rebuild everything. You’re getting HSQLDB errors because Grails falls back to its default in-memory database when it can’t connect to MySQL. Once you declare the MySQL dependency correctly, your DataSource.groovy config should work and the tables will get created in your MySQL database.