Configuring MySQL with Grails

Here are the steps to configure your Grails application to work with a MySQL database.

  1. Put the MySQL Connector J driver class in the lib folder of your Groovy App.
  2. In the DataSource.groovy file remove the default HSQLDB information and replace with MySQL specific configuration. (Sample file using a database called 'books' is shown below)

dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "admin"
}

hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}

// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop"
url = "jdbc:mysql://localhost:3306/books"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/books"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/books"
}
}
}